2楼解释了是特殊符号,起个连接作用,相当于把col2和col3用特殊符号连接起来作为一个字段去处理,一个字段的in会写吧![/quote]
比如我要查Col1和Col2,可以写成
select * from t where cast(col1 as varchar) + '@' + cast(col2 as varchar) in ('1@2','2@1', '3@3', ....)
是这个意思吗?相当于把多列合成一个列来查询?@AcHerat
我试试
declare @t table(col1 int,col2 int)
insert into @t
values(1,2),(2,1),(3,3)
--select * from @t
select * from T inner join @t tt on tt.col1 = t.col1 and tt.col2 = t.col2
另外也不建议你这么做,能说说具体逻辑么?
难道不能用
select * from t where col2 = ? and col3 = ?
这种语法查询数据?
如果是多行数据,先把你输入的数据做一个临时表 @t ,执行查询
select * from t as a where exists (select 1 from @t as b where a.col2 = b.col2 and a.col3 = b.col3)
请问各位大神,当要查找的键值对比较多的时候,两种写法哪个效率高?
一:
select * from t where cast(col1 as varchar) + '@' + cast(col2 as varchar) in ('1@2','2@1', '3@3', ....)
二:
declare @t table(col1 int,col2 int)
insert into @t
values(1,2),(2,1),(3,3)
--select * from @t
select * from T inner join @t tt on tt.col1 = t.col1 and tt.col2 = t.col2