您當前位置:
首頁 >
數據庫 >
Sqlserver > SQL 2005使用PARTITION and Rank實現group by to
SQL 2005使用PARTITION and Rank實現group by to
來源:程序員人生 發布時間:2014-04-10 14:19:25 閱讀次數:3432次
DEMO1:
select * from
(
select Player, Year, HomeRuns, Rank() over (Partition BY Player order by HomeRuns DESC, Year DESC) as Rank
from
Batting
) tmp
where Rank = 1
DEMO2:
WITH ttts AS (
Select JournalID,ParentID,RANK() OVER (partition by ParentID orDER BY JournalID asc) AS rt From Journal_Category Where ParentID in (Select JournalID from Journal_Category where ParentID = 1) Group By ParentID,JournalID
)
Select * from ttts where ttts.rt <=1
輕松實現Group By Top
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈