熟悉sql的兄弟看过来
有两个表,table1 和 table2
二者均有一个id字段,table1中的id类型为Int
table2中的id类型为varchar
表中的数据如下:
table1
-----------------------
id name ....
1 zhangsan ...
2 lisi ...
3 wangwu ...
table2
------------------------
id city
1 a
1,2 b
如何判断table1中某个记录中的id是属于table2中某个记录的id的一个值?
例如"1"在"1,2"中
问题点数:20、回复次数:3Top
1 楼zarge(鲨去来兮)回复于 2005-02-24 17:27:28 得分 10
select * from table1 t1, table2 t2 where t2.id like '%' + t1.id + '%'Top
2 楼didoleo(冷月无声)回复于 2005-02-24 17:30:10 得分 10
楼上的稍微有点笔误
select t1.* from table1 t1, table2 t2 where t2.id like '%' + cast(t1.id as varchar) + '%'Top
3 楼xluzhong(Ralph)回复于 2005-02-24 17:41:48 得分 0
create table test0502241(id int,mark nvarchar(10))
insert into test0502241 select 1,'一般'
union all select 2,'特殊'
create table test0502242(id nvarchar(10),mark nvarchar(10))
insert into test0502242 select '1','一般'
union all select '1,2','特殊'
select *
from test0502241 t1,test0502242 t2
where len(t2.id)-len(replace(t2.id,t1.id,''))>0
drop table test0502241
drop table test0502242
Top




