如何获得前5名的不同 [英] How to get top 5 distinct
本文介绍了如何获得前5名的不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两张桌子1.table的视频看起来像
VideoID int
VideoTitle varchar(max)
Videodescripton等.. 。
和第二个表评论有
CommentID
VideoID
评论等..
现在我想从评论表中获得前5个最新视频ID我将如何做到这一点...通过使用distinct不是解决方案..
解决方案
使用TOP http://msdn.microsoft。 com / en-us / library / ms189463.aspx 降序排列。
是的,我做了但是它重复了数据..假设同一个视频被评论两次,在top5中按降序排列,相同的视频ID将出现两次.. :(任何建议请?
这不应该发生。你的查询有问题。发布你的内容使用
i have two tables 1.table of videos which looks like
VideoID int
VideoTitle varchar(max)
Videodescripton etc...
and second table Comments which has
CommentID
VideoID
Comments etc..
now i want to get top 5 latest videos ids from the comments table how i will do that.. by using distinct is not the solution..
解决方案
Use TOP http://msdn.microsoft.com/en-us/library/ms189463.aspx with descending order.
yeah i did that but it repeats the data.. suppose a same video is commented twice, the in top5 in descending order, the same video id will be present twice.. :( any suggestions please ??
That should not happen. There is something wrong with your query. Post what you used.
这篇关于如何获得前5名的不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文