我有 3 个表:
threads (thread_id and thread_title)
tags (tag_id and tag_name)
tag_thread (pivot only with thread_id and tag_id)
如何制定一个查询,给出最近 100 个条目中出现次数最多的 5 个标签的名称?
最佳答案
这将为您提供最新 100 个主题的前 5 个标签
select ta.tag_name
from tags ta
join tag_thread tt on tt.tag_id = ta.tag_id
join
(
select * from threads order by thread_id desc limit 100
) th on tt.thread_id = th.thread_id
group by ta.tag_name
order by count(tt.thread_id) desc
limit 5
关于MySQL 查询通过数据透视表返回最常用的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44929459/