表“temp”中有375个拨号代码:
917277
917278
918083
...
9172738
我可以做以下事情:
select * from cdr where
dnis like 917277% or
dnis like 917278% or
dnis like 918083% or
...
dnis like 9172738%
是否可以进行包含“select in”和“like%”条件的查询?
select * from cdr where dnis in (select dialcode% from temp)
答案 0 :(得分:1)
您可以使用JOIN
和LIKE
来获得类似的结果:
SELECT c.* -- DISTINCT may be needed if dialcodes overlap each other
FROM cdr c
JOIN temp t
ON c.dnis LIKE t.dialcode || '%'
答案 1 :(得分:1)
一种方法是使用exists
:
select c.*
from cdr c
where exists (select 1 from temp t where c.dnis like dialcode || '%' );
请注意,即使可能存在多个匹配项,也不需要distinct
。