質問

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