开发者

Many-to many query

given a relation like this:

|Posts |   |Taggins |     |Tags| 
|------|   ----------     ------
| id   |   |  id    |     | 开发者_如何转开发id |
           | post_id|     
           | tag_id |

I want to find 5 tags with the biggest amount of posts.

I am quite confused how I should approach it with joins and count, as I can't get anything right so far.


Something like this?

SELECT TOP 5 tag_id, count(*) cnt
FROM Taggins
GROUP BY tag_id
ORDER BY cnt DESC
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜