这种效果如何统计?
原帖:地址http://bbs.csdn.net/topics/390294973
select 字段ID,字段2,字段3,字段4,stuff((select ','+字段23 from table2 where table2.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段23 ,stuff((select ','+字段33 from table3 where table3.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段33,stuff((select ','+字段43 from table4 where table4.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段43 ,stuff((select ','+字段53 from table5 where table5.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段53 from table1 tb1 where tb1.字段id in (select 字段id from table3 where 字段33='张三' )
这样的话 把李四也带出来了 ,
能不能 我只查 张三就出来张三这条数据 李四的字段ID虽然是同一个 但是安这个人查的话 希望不要出来李四
能查么??
[最优解释]
stuff((select ','+字段33 from table3 where table3.字段ID=tb1.字段ID for xml path('')),1,1,'') 字段33
改为张三就行了
[其他解释]
stuff((select ','+字段33 from table3 where table3.字段ID=tb1.字段ID and 字段33 in('张三') for xml path('')),1,1,'') 字段33
[其他解释]
呵呵 stuff这个关键字看来还是很有用的嘛?
[其他解释]