Sybase: HAVING operates on rows?

后端 未结 3 1871
Happy的楠姐
Happy的楠姐 2021-01-24 00:56

I\'ve came across the following SYBASE SQL:

-- Setup first
create table #t (id int, ts int)
go

insert into #t values (1, 2)
insert into #t values (1, 10)
insert         


        
3条回答
  •  盖世英雄少女心
    2021-01-24 01:28

    I haven't done Sybase since it shared code with MS SQL Server....90's, but my interpretation of what you are doing is this:

    First, the list is filtered to <= 11

    id   ts
    1    2
    1    10
    2    5
    

    Everything else is filtered out.

    Next, you are filtering the list to the rows where TS = the Max(TS) for that group.

    id   ts
    1    10
    2    5
    

    10 is the Max(TS) for group 1 and 5 is the Max(TS) for group 2. Those two rows are the ones that remain. What result would you expect otherwise?

提交回复
热议问题