create table Demo
(
id int identity(1,1) primary key,
name varchar(100),
tel varchar(100)
)
insert into Demo values('小明','13333332222')
insert into Demo values('小李','13833332222')
insert into Demo values('小张','15933332222')
insert into Demo values('小赵','13333338899')
insert into Demo values('小王','13888888888')
--查询号码包含2222的
select * from Demo where tel like '%2222%'
--查询手机号是133开头的
select * from Demo where tel like '133%'
--查询尾号是8899的
select * from Demo where tel like '%8899'
--查询ID在 2 3 4之间的
select * from demo where id in(2,3,4)
很简单的问题 大家都能会做.但是大家又都说 like in 效率不行.. 那代码改如何?
我只能想到
select * from demo where CHARINDEX('2222',tel)>0
select * from demo where left(tel,3)='133'
select * from demo where right(tel,4)='8899'
select * from demo where id=2
union all select * from demo where id=3
union all select * from demo where id=4
2,很明显
2.1 select * from demo where id in(2,3,4)
2.2 select * from demo where id=2 or id=3 or id=4
2.3 select * from demo where id=2 union all select * from demo where id=3 union all select * from demo where id=4