문제

I have a table that maintains information related to video and their likes.

enter image description here

So i want to get most liked videoid for that i queried the following way

select VideoId,count(LikeStatus) from Likes where Status='0' group by VideoId

I get the following output

enter image description here

works fine but i need this query to be nested query i mean

select title,desc from videos where videoID IN (select VideoId,count(LikeStatus) from Likes where Status='0' group by VideoId)

I know that sub query must return only one field, so is there any other good method?

도움이 되었습니까?

해결책

Something like this?

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

다른 팁

If I understant well you try to do bellow code (?)

SELECT title,desc 
FROM videos V
LEFT JOIN Likes L ON V.id = L.VideoId

WHERE (select count(LikeStatus) from Likes DL where DL.Status='0' AND DL.VideoId = V.id group by DL.VideoId) > 0

GROUP BY V.id

ORDER BY (select count(LikeStatus) from Likes DL where DL.Status='0' AND DL.VideoId = V.id group by DL.VideoId) DESC

Am I right?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top