SQL 2005使用PARTITION and Rank實現(xiàn)group by to
來源:程序員人生 發(fā)布時間:2014-04-10 14:19:25 閱讀次數(shù):3423次
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
輕松實現(xiàn)Group By Top
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進(jìn)行捐贈