id  pid  type
1    1    2
2    1    7
3    1    8
4    2    8
5    3    7
6    3    8
表结构如上。
pid 与 id 没有任何关系
取出来这两种数据:
1。pid 为 2 的,因为 type 只等于 8
2。pid 为 3 的,因为 type 只有等与 7 与等于 8 的
注:pid 为 1 的不需要,因为有一个 type=2,所以不取。
对不起大家了,没描述清楚。 就是要取type=8的或仅有type=8及type=7的pid。 上述例子中,符合条件的只有2,3
|  |      1VeryZero      2019-06-18 17:49:27 +08:00  2 完全不知道在说啥。。 | 
|  |      2iblislsy      2019-06-18 18:30:50 +08:00 完全不知道在说啥。。 | 
|  |      3AngryPanda      2019-06-18 18:32:32 +08:00 语文不及格。 | 
|      4KannaMakino      2019-06-18 18:40:34 +08:00 via iPhone ??? | 
|      5ashlord      2019-06-18 18:42:22 +08:00 额所以问题呢? | 
|      6sharpless      2019-06-18 18:48:52 +08:00 via Android 表达的很不准确 | 
|  |      7akira      2019-06-18 18:57:26 +08:00 1。pid 为 2 的,因为 type 只等于 8 // pid=2 和 type=8 有什么逻辑关系? 2。pid 为 3 的,因为 type 只有等与 7 与等于 8 的 // pid=3 和 type=7/8 又是什么逻辑关系 注:pid 为 1 的不需要,因为有一个 type=2,所以不取 // pid=1 和 type =2 又又是什么逻辑关系 | 
|      8lyy16384      2019-06-18 19:18:00 +08:00 说实话你的附言依然看不懂 | 
|  |      91010543618      2019-06-18 19:36:57 +08:00 感觉可以这样 xxx 代表一些 procedure select pid from (select xxx(type) as type_str, pid group by pid) where xxx(type_str) | 
|  |      101010543618      2019-06-18 19:38:52 +08:00 貌似是要根据某个 pid 是否只包含某个 type,找出符合的 pid | 
|  |      11RRRoger      2019-06-18 19:51:17 +08:00 SELECT * FROM  table1 a WHERE NOT EXISTS (SELECT 1 FROM table1 b WHERE a.pid=b.pid AND a.type <b.type) | 
|      12maierhuang      2019-06-18 19:56:41 +08:00 select * from t1 where pid in (select distinct pid from t1 where type in (7,8)  and pid not in (select distinct pid from t1 where type !=7 and type !=8)); |