我们想把多列值显示成单列,下面用逗号分隔的值就是我的表数据下面是我正在尝试的sql查询:
select name, STUFF((SELECT '; ' + facilty FROM leads Name FOR XML PATH('')),1,2,'') as facilty, address from leads
查询结果现在,当我在sql server中执行查询时,我希望它如下所示:
ubof19bj1#
使用where子句:
select name , STUFF((SELECT '; ' + facilty FROM leads FOR XML PATH('') ),1,2,'') as facilty, address from leads where name is not null;
5jdjgkvh2#
使用 string_agg() :
string_agg()
select max(name), string_agg(facility, ','), max(address) from leads group by leadid;
2条答案
按热度按时间ubof19bj1#
使用where子句:
5jdjgkvh2#
使用
string_agg()
: