我有一个表,维护与视频和他们喜欢的信息。
所以我想得到大家最喜欢的视频ID
选择VideoId,count(LikeStatus)from Likes where Status='0'按VideoId分组
我得到以下输出
很好,但我需要这个查询是嵌套查询
select title,desc from videos where videoID IN (select VideoId,count(LikeStatus) from Likes where Status='0' group by VideoId)
我知道子查询必须只返回一个字段,那么还有其他好方法吗?
最佳答案
像这样的?
SELECT *
FROM Videos
INNER
JOIN (
SELECT VideoId
, Count(*) As number_of_likes
FROM Likes
WHERE Status = '0'
GROUP
BY VideoId
) As likes
ON likes.VideoId = Videos.VideoId
关于mysql - 查询以检索最受欢迎的视频,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19789451/