首页 > mysql in出现次数排序

mysql in出现次数排序

三个表:artice,tag,map。map表记录了一篇article的tag,现在读出一篇article,然后根据tag查找相关性最高的其他artice,用什么方法最好?用mysql in(tagid1,tagid2,tagid3)这样的形式,能不能根据in里面出现的次数来排序?


这种最好用全文搜索来做。


select
*
from map as m
left join (
select tagid, count(tagid) as c from map
where tagid in (tag1, tag2, tag3)
group by tagid 
-- order by count(tagid) desc
) as ct on m.tagid=ct.tagid
left join article as a on m.articleid=a.id
order by ct.c desc
【热门文章】
【热门文章】