龚哥哥 - 山里男儿 爱生活、做自己!
MySQL查询重复出现次数最多的记录
发表于 2015-8-31 | 数据库

单表查询

SELECT DISTINCT COUNT(*) AS count, lid FROM user_label GROUP BY lid ORDER BY count DESC LIMIT 0, 10;

联表查询user_label 用户标签关联表(uid, lid), label 标签表(lid, name)

SELECT DISTINCT count(u.lid) AS count, u.lid, l.name FROM `label` AS l INNER JOIN `user_label` AS u ON u.lid=l.lid GROUP BY u.lid ORDER BY count DESC LIMIT 0, 10

发表评论:

TOP