我有表格媒体、标签、标签内容
c_媒体
mid (primary)
m_title (varchar)
m_date (int 11, unix timestamp) index
标签
t_id (primary)
t_name (varchar)
t_type (varchar)
key: tag (columns t_name, t_type)
标签内容
tc_id (int 11) (same as t_id from tags table)
tc_cid (int 11) (same as mid from c_media table)
key: tc (columns tc_id, tc_cid)
目标是从具有共同标签(在本例中为 162)且在过去 24 小时内创建的故事中获取热门标签。这似乎有效,但速度很慢,感谢您的帮助。
SELECT t_id, t_name, t_type, COUNT(t2.tc_id) AS total_tags FROM c_media
INNER JOIN tag_content t1 ON t1.tc_cid = mid AND t1.tc_id = '162'
INNER JOIN tag_content t2 ON t2.tc_cid = t1.tc_cid AND t2.tc_id != t1.tc_id
LEFT JOIN tags ON t_id = t2.tc_id
WHERE m_date > UNIX_TIMESTAMP( now( ) -86400 )
AND t_type NOT IN ('Topic', 'Position')
GROUP BY t2.tc_id
ORDER BY total_tags DESC
LIMIT 30