如何在sql server中将多行连接到一个字段中
使用简单的查询,我可以做如下事情如何在sql server中将多行连接到一个字段中,sql,sql-server,database,Sql,Sql Server,Database,使用简单的查询,我可以做如下事情 SELECT hobbies FROM peoples_hobbies WHERE person_id = 5; 并获得: shopping fishing coding 但我只想要一行,一列: shopping, fishing, coding 参考—— 我想在sql server中实现这一点???sql server不太支持聚合字符串连接。但你可以做到: select stuff((select ', ' + hobbies
SELECT hobbies FROM peoples_hobbies WHERE person_id = 5;
并获得:
shopping
fishing
coding
但我只想要一行,一列:
shopping, fishing, coding
参考——
我想在sql server中实现这一点???sql server不太支持聚合字符串连接。但你可以做到:
select stuff((select ', ' + hobbies
from peoples_hobbies
where person_id = 5
for xml path ('')
), 1, 2, '') as hobbies;