SELECT meterid ,
stuff((select ','+alarm from t_xhs_alarm_hie_copy
where c.meterid=meterid for xml path('')),1,1,'') as alarm
from t_xhs_alarm_hie_copy c group by c.meterid
t_xhs_alarm_hie_copy :表
meterid:是根据这一字段,该字段相同的进行合并
alarm:合并的是该字段