13
SELECT * FROM abc WHERE column1 IN (a1,b1,c1)

I want to use LIKE with this select query; how can I write LIKE statement with IN, similar to the query below:

SELECT * FROM abc WHERE column1 LIKE IN (a%,b%,c%)
4

4 回答 4

12

You can't combine like with in. Write it as separate comparisons:

select column1
from abc
where column1 like 'a%' or column1 like 'b%' or column1 like 'c%'
于 2012-08-07T03:41:13.527 回答
6

You can't. Write it as:

column1 LIKE 'a%' OR column1 LIKE 'b%' OR column1 LIKE 'c%'
于 2012-08-07T03:40:17.373 回答
2

正如其他人所说,您可以使用 OR 条件列表来指定条件。

您还可以在 from 子句中使用临时表或子查询。以下是 from 子句中的子查询示例:

select column1
   from abc
   , table(
       (select 'a%' as term from SYSIBM.SYSDUMMY1)
       union all
       (select 'b%' from SYSIBM.SYSDUMMY1)
       union all
       (select 'c%' from SYSIBM.SYSDUMMY1)
   ) search_list
   where abc.column1  like search_list.term;
于 2012-08-07T03:58:13.243 回答
0

如果您真的想查找以 a、b 或 c 开头的字符串,您可以选择:

SELECT * 
FROM abc
WHERE LEFT(column1, 1) IN ('a', 'b', 'c')

我认为你的情况实际上更复杂,但也许你可以根据你的需要调整这个片段......

于 2020-02-24T14:37:17.993 回答