Merge multiple rows into one column without duplicates

后端 未结 4 738
轻奢々
轻奢々 2021-02-01 02:44

I am working on a query that will collect data from a table and display the data for a report.

The data looks like this:

Player Score
001      10
001           


        
4条回答
  •  野性不改
    2021-02-01 03:44

    For SQL Server you can use:

    select player,
      stuff((SELECT distinct ', ' + cast(score as varchar(10))
               FROM yourtable t2
               where t2.player = t1.player
               FOR XML PATH('')),1,1,'') 
    from yourtable t1
    group by player
    

提交回复
热议问题