标签: mysql
例如:
数据库:
在mysql命令之后会出现这些结果:
感谢您的耐心等待。
答案 0 :(得分:1)
您可以使用聚合和UNION ALL这样:
UNION ALL
SELECT name FROM t GROUP BY name HAVING COUNT(*) <= 2 UNION ALL SELECT name FROM t WHERE name NOT IN ( SELECT name FROM t GROUP BY name HAVING COUNT(*) <= 2 );