场景一 某表中 id,name,sex 根绝 id 分组 将一组的name 相加用逗号隔开 将sex 相加用逗号隔开
用到的sql 函数 for xml 和 STUFF
SELECT
id,
[name] = stuff(
(
SELECT
',' + [name]
FROM
tabla AS a
WHERE
a.id= b.id for xml path ('')
),
1,
1,
''
),
[sex] = stuff(
(
SELECT
',' + [sex]
FROM
tabla AS a
WHERE
a.id = b.id FOR xml path ('')
),
1,
1,
''
)
FROM
tabla AS b
GROUP BY
id