日期:2014-05-17  浏览次数:20403 次

查询的结果用逗号连接 有图



SQL怎样写能变成下面这张图


------解决方案--------------------
create table #table(baomingzy varchar(50),call_user varchar(50))

insert into #table
select '','jiangbingyu' union all
select '','jiangshengnan' union all
select '','menglingjun' union all
select '办公自动化','jiangshengnan' union all
select '初级会计实务','jiangshengnan' union all
select '电脑应用高级班','jiangshengnan' union all
select '海洋自动化精+串','jiangshengnan' union all
select '会计就业直通班','jiangshengnan' union all
select '会计学串讲','jiangshengnan' union all
select '中级会计师','jiangshengnan' union all
select '专升本VF+英语','jiangshengnan' 

select distinct
(select stuff((
select ','+baomingzy from #table b where a.call_user=b.call_user
for xml path('')),1,1,''))baomingzy
,call_user
from #table a

baomingzy                                                                                                                                                                                                                                                        call_user
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------