我有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 - MySQL查询通过数据透视表返回最常用的标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44929459/