软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > 网络编程 > SQL SERVER > SQL 2005使用PARTITION and Rank实现group by to

SQL 2005使用PARTITION and Rank实现group by to

DEMO1:
Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com]
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:
Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com]
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

    相关阅读
    网友评论
    栏目导航
    推荐软件