日期:2014-05-17 浏览次数:20564 次
select typename, awardname = stuff((select ',' + awardname from T_Award t where typename = T_Award.typename for xml path('')) , 1 , 1 , '') from T_Award group by typename
select a.personName,d.awardName ,c.activityName,d.typeName from T_Person a join T_PersonAwardR b on a.id=b.personId join T_Activity c on b.activityId=c.id join T_Award d on d.id=b.awardId where c.activityName='万人长跑大赛' and d.typeName='优秀主持人奖';
;with cte as ( select a.personName,d.awardName ,c.activityName,d.typeName from T_Person a join T_PersonAwardR b on a.id=b.personId join T_Activity c on b.activityId=c.id join T_Award d on d.id=b.awardId where c.activityName='万人长跑大赛' and d.typeName='优秀主持人奖'; ) select distinct awardName, 获奖人员名单=stuff((select ','+personName from cte where t.awardName=awardName for xml path('')),1,1,'') from cte t