我的桌子如下
我想要输出如下
我尝试做以下事情
SELECT * FROM TABLE_NAME WHERE COLUMN2 = 'PQR' AND COLUMN3 IS NOT NULL
但是它也会从第一张表中删除3rd and 4th row
。而在查询的输出中,我只需要删除具有Column2 as PQR and Column3 as NOT NULL
我也尝试使用case
语句,但是我无法真正了解如何实现它。
编辑1:-
我还想现在再尝试一件事。
SELECT * FROM TABLE_NAME WHERE COLUMN2 IN ('PQR', 'XYZ', 'RST') AND COLUMN3 IS NOT NULL
但是问题出在实际的表COLUMN2
中,有150多个不同的值,我无法在IN
子句中继续提及。
答案 0 :(得分:0)
您想要的是(如果我理解正确的话)
NOT (COLUMN2 = 'PQR' AND COLUMN3 IS NOT NULL)
等效于
COLUMN2!='PQR' OR COLUMN3 IS NULL
答案 1 :(得分:0)
示例:
SQL> ;
1 with -- test data:
2 t(column1,column2,column3) as (
3 select 'ABC','PQR',cast(null as int) from dual union all
4 select 'DEF','PQR',123 from dual union all
5 select 'GHI','XYZ',cast(null as int) from dual union all
6 select 'JKL','RST',cast(null as int) from dual
7 ) -- test query:
8 select *
9 from t
10* where not(COLUMN2 = 'PQR' AND COLUMN3 IS NOT NULL)
SQL> /
COL COL COLUMN3
--- --- ----------
ABC PQR NULL
GHI XYZ NULL
JKL RST NULL
或lnnvl(COLUMN2 ='PQR')或COLUMN3为NULL
示例:
with -- test data:
t(column1,column2,column3) as (
select 'ABC','PQR',cast(null as int) from dual union all
select 'DEF','PQR',123 from dual union all
select 'GHI','XYZ',cast(null as int) from dual union all
select 'JKL','RST',cast(null as int) from dual
) -- test query:
select *
from t
where lnnvl(COLUMN2 = 'PQR') or COLUMN3 IS NULL;
COL COL COLUMN3
--- --- ----------
ABC PQR NULL
GHI XYZ NULL
JKL RST NULL