sql多行合并成一行
sql server
SELECT [activityId],
--STUFF(
(SELECT ',' + Cast(A.phone AS varchar)
FROM aaa A
WHERE A.activityId=B.activityId
FOR XML PATH(''))
--,1,1,'') AS phones
FROM aaa B
GROUP BY [activityId]
mysql
SELECT
activityId,
group_concat(DISTINCT phone ORDER BY phone DESC SEPARATOR ';') AS phones
FROM
aaa
GROUP BY
activityId