当前位置:首页 > 数据库 > MS SQL Server > SQL 2005使用PARTITION and Rank实现group by to

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

2017-01-06 | 来源:网络 | | 人气: | 关键字: sqlpartitionby sqlpartitionby
DEMO1:select * from ( select Player, Year, HomeRuns, Rank() over (Partition BY Player order by HomeR
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 Journwww.alonely.com.cnal_Category where ParentID = 1) Group By ParentID,JournalID

)

Select * from ttts where ttts.rt <=1

轻松实现Group By Top

评论

评论数10

表情
发表评论
网友评论仅供其表达个人看法,并不表明网易立场。
《SQL 2005使用PARTITION and Rank实现group by to》更多评论

头条推荐

阅读下一篇

查询数据库指定字段重复项的一条数据

网(LieHuo.Net)教程 如何SQL SERVER 查询数据库指定字段重复项的一条数据,今天小编在博客园看到该问题的实例命令代码,现在特别转载了分享给各位访客,希望对您有所帮助。 ... 查看全文

返回MS SQL Server 返回网站首页