1、如图,绑定了所有id的有A,B两个name
2、第一种Sql及效率
explain SELECT name,count(id) as count from test GROUP BY name
HAVING count(id)=(SELECT count(DISTINCT id) from test);
3、第二种sql及效率
explain select * from (SELECT name,count(id) as count from test GROUP BY name )t1
WHERE t1.count=(SELECT count(DISTINCT id) from test);