不知道mysql应该是怎么搞的
sql server 中这么搞才可以
你那样不行看看到现在没有人回答
我就用sql server 写了一下
你参考一下吧 新年快乐
------------------------------------------
create table #user(id int ,shopid varchar(10))
insert into #user
select 1 , '1,2,3'create table #shop(shopid int , shopName varchar(10))
insert into #shop
select 1 ,'aa'
union select 2 ,'bb'
union select 3 ,'cc'declare @sql varchar(20)
select @sql = shopid from #user where id =1
set @sql = 'select * from #shop where shopid in ('+@sql+')'
exec(@sql)/*
shopid shopname
---------------------
1 aa
2 bb
3 cc*/--删除测试数据
drop table #user
drop table #shop
sql server 中这么搞才可以
你那样不行看看到现在没有人回答
我就用sql server 写了一下
你参考一下吧 新年快乐
------------------------------------------
create table #user(id int ,shopid varchar(10))
insert into #user
select 1 , '1,2,3'create table #shop(shopid int , shopName varchar(10))
insert into #shop
select 1 ,'aa'
union select 2 ,'bb'
union select 3 ,'cc'declare @sql varchar(20)
select @sql = shopid from #user where id =1
set @sql = 'select * from #shop where shopid in ('+@sql+')'
exec(@sql)/*
shopid shopname
---------------------
1 aa
2 bb
3 cc*/--删除测试数据
drop table #user
drop table #shop
where b.id = 1 and INSTR(b.shopid, a.shopid);
作为调试如下:
先判断:select shopid from user 能返回几条记录。
这句分成两句的:
先select shopid from user where id=1
得出shopid='1,2,3'
然后select * from shop where shopid in ($shopid)这样就可以得出3条记录,可把两句合并怎么就不行了呢
select a.* from shop a ,user b
where b.id = 1 and INSTR(b.shopid, a.shopid);
明晚来结贴了