Sybase: HAVING operates on rows?
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 into #t values (1, 20) insert into #t values (1, 30) insert into #t values (2, 5) insert into #t values (2, 13) insert into #t values (2, 25) go declare @time int select @time=11 -- This is the SQL I am asking about select * from (select * from #t where ts <= @time) t group by id having ts = max(ts) go The results of this SQL are id ts ----------- ----------- 1 10 2 5 This looks like HAVING condition applied to rows rather than groups.