Merge multiple rows with same ID into one row

前端 未结 3 1699
逝去的感伤
逝去的感伤 2020-12-31 13:19

How can I merge multiple rows with same ID into one row.

When value in first and second row in the same column is the same or when there is value in fi

3条回答
  •  天命终不由人
    2020-12-31 13:37

    You can try something like this:

    select 
    isnull(t1.A, t2.A) as A,
    isnull(t1.B, t2.B) as B,
    isnull(t1.C, t2.C) as C
    from
    table_name t1
    join table_name t2 on t1.ID = t2.ID and ..... 
    

    You mention the concepts of first and second. How do
    you define this order? Place that order defining condition
    in here: .....

    Also, I assume you have exactly 2 rows for each ID value.

提交回复
热议问题