首页 > 代码库 > 一条很用的MSSQL语句
一条很用的MSSQL语句
select *,ActionName= stuff((select ‘,‘ + ActionName from Sys_Action_Table where ModuleId = Sys_Module_Table.ModuleId for xml path(‘‘)) , 1 , 1 , ‘‘) from Sys_Module_Table
查询结果
with awardT 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 B.awardName,LEFT(awards,LEN(awards)-1) as awards FROM (SELECT awardName,(SELECT personName+‘,‘ FROM awardT WHERE awardName=A.awardName for xml path(‘‘)) as awardsfrom awardT A group by awardName) B
SELECT a.awardnaame ,
STUFF(( SELECT ‘,‘ + table1.personname
FROM table1
WHERE table1.awardnaame = a.awardnaame
FOR
XML PATH(‘‘)
), 1, 1, ‘‘) AS personname
FROM ( SELECT awardnaame
FROM table1
GROUP BY awardnaame
) a
一条很用的MSSQL语句
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。