SELECT (
CASE `table1`.`parent_code`
WHEN '01'
THEN '媒体'
WHEN '02'
THEN '品牌'
WHEN '03'
THEN 'BD'
END
) AS 一级名称, `table1`.`name` AS 二级名称, `table2`.`name` AS 三级名称
FROM `table2`
LEFT JOIN `table1` ON ( `table1`.`code` = `table2`.`parent_code` )
WHERE `table2`.`name`
IN (
SELECT `name`
FROM `table2`
GROUP BY `name`
HAVING count(*) >1
)
按照name分组并统计name出现的次数,HAVIN过滤分组信息
SELECT `name`, count(*) FROM `table2` GROUP BY `name` HAVING count(*) > 1