MSSQL 分組後取每組第一條(group by order by)
--根據 x 分組後、根據 y 排序後取第一條 select * from ( select ROW_NUMBER() over(partition by x order by y desc) RowNum ,testTable.* from testTable) as t1 where RowNum = 1
MySQL分組取每組前一(或幾)條記錄(排名)
--根據 x 分組後、根據 y 排序後取第一條 select * from ( select ROW_NUMBER() over(partition by x order by y desc) RowNum ,testTable.* from testTable) as t1 where RowNum = 1