SQLSERVER 查询分组后获取每组的最新一条数据

代码如下

select  from (
    select 
        row_number() over(partition by x order by y desc) as rid
        ,
    from z
) as tt
where tt.rid=1
--按x分组,以y排序

相关推荐