标签:
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查询..
我有一个问题,我是初学者
答案 0 :(得分:1)
SELECT id_tags, count(id_post) as id_post_count
FROM tags_id
GROUP BY id_tags
答案 1 :(得分:0)
有关获取“每个标签有多少帖子”的答案,请参阅@gontrollez。
要回答“每篇帖子有多少个标签”,请参阅:
SELECT id_post, COUNT(id_tags) AS id_tags_per_post_count
FROM tags_id
GROUP BY id_post
ORDER BY 2, 1
答案 2 :(得分:0)
尝试以下查询:
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