select name,(select count(*) from table1 where id in (table2.idSum)) from table2
当table2的idSum =2 是对的
但 当idSum =2,3,4,5 的时候就没数据了。。真是搞晕了。
------解决思路----------------------
idSum =2时,语句相当于:select name,(select count(*) from table1 where id in ('2')) from table2,会有记录。
idSum =2,3,4,5时,语句相当于:select name,(select count(*) from table1 where id in ('2,3,4,5')) from table2,不会有记录。
------解决思路----------------------
select name,(select count(*) from table1 where charindex(','+rtrim(id)+',',','+table2.idSum+',')>0) from table2