在DB2中组合IN和LIKE函数
在DB2中有没有一种方法可以将IN和LIKE函数组合在一起?例如,我想排除具有userid A、B、C以及从X%或Y%开始的userid的用户。我尝试了下面的查询,但它不起作用在DB2中组合IN和LIKE函数,db2,Db2,在DB2中有没有一种方法可以将IN和LIKE函数组合在一起?例如,我想排除具有userid A、B、C以及从X%或Y%开始的userid的用户。我尝试了下面的查询,但它不起作用 select * from table where userid not in ('A','B','C') or (not like 'X%' or not like 'Y%') 您可以使用中的中使用的所有常量,如: with table (userid) as ( values 'A', 'AA', 'XX'
select * from table where userid not in ('A','B','C') or (not like 'X%' or not like 'Y%')
您可以使用
中的中使用的所有常量,如:
with
table (userid) as
(
values 'A', 'AA', 'XX', 'YY', 'ZZ'
)
, vals (userid) as
(
values 'A', 'B', 'C', 'X%', 'Y%'
)
select *
from table t
where not exists
(
select 1
from vals v
where t.userid like v.userid
);
结果是:
|USERID|
|------|
|AA |
|ZZ |
使用“AND”代替“OR”
select * from table
where userid not in ('A','B','C')
and userid not like 'X%'
and userid not like 'Y%'