一个高效的查询我有一个看起来像这样究竟是什么任务
item_id | status
1 | null
2 | null
2 | new
3 | new
4 | null
4 | new
5 | null
注意,第2项和第4兼得2种状态的数据文件:空和新的。 我想创建一个查询,只提取1状态,这是null的item_id。所以,我想我的查询,只提取1和5
我落得这样做,但是这看起来并不高效:
1.List项目与空状态
create table query_1 as
select * from table1 where status = 'null';
2与新的状态
create table query_2 as
select * from table1 where status = 'new';
3.select从查询1中的所有结果,但不包括从查询结果中发现有任何ID的.List项目2
select * from query_1 where item_id not in (select item_id from query_2)
我在想这个吗?有没有更简单的查询可以实现这一点?
首先,你必须一起检查空值'IS NULL'。 '= null'或'='null''将不起作用。 – Stavr00