sql 分組后每組取第一個


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分組取每組前一(或幾)條記錄(排名)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM