3
我得到以下结果:需要帮助加盟三个表后生成查询
col1 col2 col3
1 2 Pr1
1 2 Pr2
1 2 Pr3
但我需要的输出是这样的:
col1 col2 col3
1 2 Pr1,Pr2,Pr3
我得到以下结果:需要帮助加盟三个表后生成查询
col1 col2 col3
1 2 Pr1
1 2 Pr2
1 2 Pr3
但我需要的输出是这样的:
col1 col2 col3
1 2 Pr1,Pr2,Pr3
在MS SQL 2005/2008:
select
col1,
col2,
col3 = (
select col3 + ','
from TestTable
for xml path('')
)
from TestTable
group by col1, col2
在这里你可以找到如何做同样在2000年,以及如何摆脱尾随逗号:Create A Comma Delimited List From a Column
我们将需要看到执行的sql – 2011-05-30 10:01:55
您的意思是... SELECT col1,col2,GROUP_CONCAT(col3)FROM table GROUP BY col1,col2? – royrui 2011-05-30 10:12:45
有没有在MS-SQL服务器中的GROUP_CONCAT – Navaneethan 2011-05-30 10:24:53