SQL中将查询的结果合并成一列
SQL中将查询的结果合并成一列
2019-06-10 13:40
会说话的哑巴hh
阅读(1994)
评论(0)
编辑
收藏
举报
其中:oracle 自带 wmsys.wm_concat(需要合并的字段)
Mysql 自带(group_concat)
Sql Server(———)
select p.KeyId,
stuff((SELECT \’,\’ + CONVERT(nvarchar, KeyId) FROM dbo.QR_Inspection WHERE propertyId = p.KeyId FOR xml path(\’\’)),1,1,\’\’) AS iid,
stuff((SELECT \’,\’ + CONVERT(nvarchar, KeyId) FROM dbo.QR_User WHERE propertyId = p.number FOR xml path(\’\’)),1,1,\’\’) AS uid
from dbo.QR_Property p
order by KeyId desc
https://blog.csdn.net/lchq1995/article/details/86615119 (还有类似问题,可以借鉴下 )