对于写partition by username order by [date], [time] desc的写法,我只想说没有产品思想的程序员太耽误事。
with t as
(
select ROW_NUMBER() OVER(partition by username, [date] order by [time] ) rn, *
from 打饭记录
where DATEPART(HOUR, [time])=12
)
select * from t where rn = 1
; with tbl as
(
select ROW_NUMBER() OVER(partition by username order by [date], [time] desc) as noid, *
from 打饭记录表
where DATEPART(HOUR, [time]) between '12' and '13'
)
select * from tbl where noid = 1