开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜