本帖最后由 Ronins 于 2013-10-22 15:26 编辑 select A.name,A.peopleid from (select name,peopleid,count(distinct sex) as 'count' from people group by name,peopleid) as A where A.count = 2;(或A.count >= 2) |
mysql> select b.name,a.peopleid from (select peopleid from people a group by peopleid having count(distinct sex)>1) a join people b on a.peopleid=b.peopleid order by a.peopleid; +-----------+--------------------+ | name | peopleid | +-----------+--------------------+ | 高会珍 | 410306197401010011 | | 高会珍 | 410306197401010011 | | 杨凤芹 | 410322194410161843 | | 杨凤琴 | 410322194410161843 | +-----------+--------------------+ 4 rows in set (0.00 sec) |
看这个例子,基本一样: http://www.mysqlpub.com/thread-34858-1-1.html |
|申请友链|小黑屋|Archiver|手机版|MySQL社区
( 京ICP备07012489号 )
联系人:周生; 联系电话:13911732319
GMT+8, 2024-5-5 23:36 , Processed in 0.068290 second(s), 30 queries , Gzip On.
Powered by Discuz! X3.2
© 2001-2013 Comsenz Inc.