[英]SQL Server - Select statement with multiple conditions from other table
[英]Oracle sql like multiple conditions with select from other table
我在表“ 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 * from cdr where dnis in (select dialcode% from temp)
您可以使用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 || '%'
一种方法是使用exists
:
select c.*
from cdr c
where exists (select 1 from temp t where c.dnis like dialcode || '%' );
请注意,即使可能存在多个匹配项,也不需要distinct
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.