MySQL社区

标题: sql语句求助 [打印本页]

作者: ywl01    时间: 2013-9-18 13:58
提示: 作者被禁止或删除 内容自动屏蔽
作者: kider    时间: 2013-9-18 15:09
看这个例子,基本一样:
http://www.mysqlpub.com/thread-34858-1-1.html
作者: ywl01    时间: 2013-9-18 15:30
提示: 作者被禁止或删除 内容自动屏蔽
作者: ywl01    时间: 2013-9-18 16:17
提示: 作者被禁止或删除 内容自动屏蔽
作者: ywl01    时间: 2013-9-20 10:42
提示: 作者被禁止或删除 内容自动屏蔽
作者: Ronins    时间: 2013-10-22 15:25
本帖最后由 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)
作者: mysqlmpp123    时间: 2016-10-30 14:29

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)




欢迎光临 MySQL社区 (http://www.mysqlpub.com/) Powered by Discuz! X3.2