开发者

T-SQL UNION query to return items with highest and lowest rating from the same table

开发者 https://www.devze.com 2023-01-15 23:00 出处:网络
I want write a stored proc in T-SQL to return the top 5 most highly 开发者_运维百科rated and the bottom 5 most lowly ratedarticles from an Articles table, determined by the \'rating\' column.

I want write a stored proc in T-SQL to return the top 5 most highly 开发者_运维百科rated and the bottom 5 most lowly rated articles from an Articles table, determined by the 'rating' column.

I was thinking of using a union on two selects but I'm not sure how to write it.


select * from (select top 5 *, 'Bottom Five' as Ranking from Call order by id ) a
union all
select * from (select top 5 *, 'Top Five' as Ranking from Call order by id desc ) b
0

精彩评论

暂无评论...
验证码 换一张
取 消