标签:
查询中经常遇到这种查询,分组后取每组第一条。分享下一个SQL语句:
--根据 x 分组后、根据 y 排序后取第一条 select * from ( select ROW_NUMBER() over(partition by x order by y desc) RowNum ,testTable.* from testTable) as t1 where RowNum = 1
注:我使用MS SQL 08 R2
MSSQL 分组后取每组第一条(group by order by)
标签:
原文地址:http://www.cnblogs.com/moretry/p/4478705.html