beagreatman

导航

 

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

posted on 2016-10-13 16:16  BeAMan  阅读(550)  评论(0编辑  收藏  举报