[英]SQL : Select row where a column of this row does't match with a certain value
我有一个表,例如,一个列id_type和另一个列num_area。 我想搜索所有id_type,其中num_area的值与某个值不匹配。
id_type num_area
---- ----
1 121
2 121
1 95
3 47
4 65
例如,如果我想要没有num_area 121的id_type,它将返回我id_type 3和4。
谢谢
计划
- 列出id_type,其中num_area是121
- 列出不在上面的独特id_type
询问
select distinct id_type
from example
where id_type not in
(
select id_type
from example
where num_area = 121
)
;
产量
+---------+
| id_type |
+---------+
| 3 |
| 4 |
+---------+
试试这个查询。 我得到的结果没有子查询。
SELECT DISTINCT(e1.id_type)
FROM example e1
JOIN example e2 ON(e1.id_type = e2.id_type AND e2.num_area != '121');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.