可以用 XML PATH來實現
SELECT T1.id, T1.type
,(SELECT [DESC] + ''
FROM @TABLE AS T2
WHERE T2.id = T1.id FOR XML PATH('')) AS [DESC]
FROM @TABLE AS T1
GROUP BY id, type
,(SELECT [DESC] + ''
FROM @TABLE AS T2
WHERE T2.id = T1.id FOR XML PATH('')) AS [DESC]
FROM @TABLE AS T1
GROUP BY id, type
而在MYSQL中,可以用GROUP_CONCAT來實現
SELECT date_format(T.T1,'%Y%m') AS d
,GROUP_CONCAT(T.ID) AS id
FROM @TABLE AS T
GROUP BY date_format(T.T1,'%Y%m')
,GROUP_CONCAT(T.ID) AS id
FROM @TABLE AS T
GROUP BY date_format(T.T1,'%Y%m')
沒有留言:
張貼留言