标签:
id, name
---------
1 tag1
2 tag2
3 tag3
4 tag4
tags_id:
id_tags, id_post
--------------
1 1
2 3
3 1
4 2
如何计算多少个帖子标签?
我需要一个mysql查询..
我对此有问题,我是初学者
SELECT id_tags, count(id_post) as id_post_count
FROM tags_id
GROUP BY id_tags
请参阅@gontrollez,以获取有关获得"每个标签有多少帖子"的答案。
回答"每个帖子有多少个标签",请参阅:
SELECT id_post, COUNT(id_tags) AS id_tags_per_post_count
FROM tags_id
GROUP BY id_post
ORDER BY 2, 1
尝试以下查询:
SELECT tags_id.id_tags, tags.name, COUNT(id_post) AS post_count
FROM tags_id
INNER JOIN tags ON tags_id.id_tags = tags.id
GROUP BY tags_id.id_tags
ORDER BY post_count DESC