Select and merge rows in a table in SQL Stored procedure

前端 未结 3 1321
梦毁少年i
梦毁少年i 2021-01-28 01:40

Have a temp table with schema: ID | SeqNo | Name

ID - Not unique
SeqNo - Int (can be 1,2 or 3). Sort of ID+SeqNo as Primary key
Name - Any text

And sam

3条回答
  •  [愿得一人]
    2021-01-28 02:04

    The solution is good. I have a similar issue, but here I am using 2 different tables. ex:

    table1 
    
    1 | 1 |
    2 | 3 |
    3 | 1 |
    4 | 2 |
    5 | 1 |
    1 | 2 |
    1 | 3 | 
    4 | 1 |
    5 | 2 |
    2 | 2 |
    4 | 3 |
    
    table2 
    1 | RecordA
    2 | RecordB
    3 | RecordC
    

    I want to get the data from two tables and display in the below format.

    1 | RecordA,RecordB,RecordC|
    2 | RecordB,RecordC|
    3 | RecordA |
    4 | RecordA,RecordB,RecordC|
    5 | RecordA,RecordB | 
    

提交回复
热议问题