我的问题是ID是否使用代码FREE25
,FREE20
和FREE10
我想忽略使用代码FREE25
和FREE20
的所有ID。< / p>
如果ID存在的代码包含FREE25
,FREE20
?
+------+--------+
| ID | Code |
+------+--------+
| 1 | FREE25 |
| 1 | FREE20 |
| 1 | FREE10 |
| 2 | FREE10 |
| 3 | FREE10 |
| 3 | FREE50 |
+------+--------+
我想输出
+------+
| ID |
+------+
| 2 |
| 3 |
+------+
答案 0 :(得分:1)
您可以使用not exists
select
distinct t1.id from table_name t1
where not exists (
select 1 from table_name t2
where t1.id = t2.id
and t2.code in ('FREE25','FREE20')
);