编写以下transact SQL的更好方法是什么?
select * from table1 where columnA like '%ABC%' and columnB = 1
select * from table1 where columnA like '%DEF%' and columnB = 1
select * from table1 where columnA like '%GHI%' and columnB = 1
是否可以将上述3个sql语句合并为单个select语句
答案 0 :(得分:4)
select * from table1
where (columnA like '%ABC%'
or columnA like '%DEF%'
or columnA like '%GHI%')
and columnB = 1
答案 1 :(得分:3)
select *
from table1
where columnB = 1 and
(columnA like '%ABC%' or
columnA like '%DEF%' or
columnA like '%GHI%')
答案 2 :(得分:0)
你可以试试这个
select * from table1
where (columnA like '%ABC%'
or columnA like '%DEF%'
or columnA like '%GHI%')
and columnB = 1