在mysql下,我会使用select ... from (select ... from... ... order by ) tmp group by ...
无奈呀,在mssql下,子句中不支持order by
最后,在偶像 @justyy的帮助下,学会了OVER(PARTITION BY)的用法
partition by 可以按字段或字段组合进行分区,然后还可以在每个分区中按字段或字段组合进行排序
OVER(PARTITION BY)则可以从每个分区中查询数据
select author, permlink,
min(DATEADD(hour,8, created)) over() (partition author,DATEADD(hour,8, created)) as time,
from comments
where DATEADD(hour,8, created)>='2018-01-27 00:00:00'
and DATEADD(hour,8, created)<='2018-02-03 00:00:00'
and permlink not like 're%'
伪程序员学习日记——边用边学边记——为了以后便于查询,也为了加强记忆。
欢迎各位偶像前来指正,不胜荣幸&感激!