2017-10-10 68 views
0

如何在MySQL运行时使用MSSQL上的GROUP_CONCAT功能?如何在MSSQL上使用GROUP_CONCAT功能

 
current table; 
    QUESTION_ID ANSWER_ID USER 
1.  1    1  A 
2.  1    1  B 
3.  1    2  C 

i need; 

    QUESTION_ID ANSWER_ID USER 
1.  1    1  A, B 
2.  1    2  C 

在此先感谢..

+0

的可能的复制[如何使用GROUP BY来连接字符串在MySQL?(https://stackoverflow.com/questions/149772/how-to-use-group-by-to-concatenate-strings-in-mysql) –

+3

[在Microsoft SQL Server 2005中模拟组\ _concat MySQL函数?](https://stackoverflow.com/ question/451415/simulating-group-concat-mysql-function-in-microsoft-sql-server-2005) –

+0

查看本[相同曲目(https://stackoverflow.com/questions/149772/how-to-use-group-by-to-concatenate-strings-in-mysql),我想这是相同的 –

回答

0

尝试:

select distinct t1.QUESTION_ID, t1.ANSWER_ID 
    STUFF((SELECT distinct '' + t2.USER 
     from yourtable t2 
     where t1.ANSWER_ID= t2.ANSWER_ID 
      FOR XML PATH(''), TYPE 
      ).value('.', 'NVARCHAR(MAX)') 
     ,1,0,'') data 
from yourtable t1; 
+0

谢谢:)我解决了这个问题 – atalay