Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

sql server - How to use GROUP_CONCAT function on MSSQL

How can I use the GROUP_CONCAT function on MSSQL while MySQL is running?

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

thanks in advance..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The equivalent function could be STRING_AGG for SQL Server 2017 and later. Note that this function not support DISTINCT filtering.

select QUESTION_ID, ANSWER_ID, STRING_AGG(USER, ', ') as USER
from t1
group by QUESTION_ID, ANSWER_ID

https://docs.microsoft.com/en-gb/sql/t-sql/functions/string-agg-transact-sql?view=sql-server-2017


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...