表:Customer
select Power,
UserName= stuff(
(
select ',' + UserName
from Customer t
where Power = t2.Power
for xml path('')
) , 1 , 1 , ''),
password= stuff(
(
select ',' + password
from Customer t
where Power = t2.Power
for xml path('')
) , 1 , 1 , '')
from Customer t2
group by Power
查询结果:
【2】对于 ORACLE SQL,使用以下方法
SELECT
CNAME,YEAR,
REPLACE(WMSYS.WM_CONCAT(ID), ',', ',') ID,
REPLACE(WMSYS.WM_CONCAT(birthday), ',', ',') birthday
FROM tb_test
GROUP BY CNAME,YEAR;
结果: