How to merge values of two rows into single row for same id?

前端 未结 2 1261
广开言路
广开言路 2021-01-27 07:32

I have data in a table(list) as shown below,

 id      no1   no2
 1000    0     511
 1000    820    0

I need data like shown below,



        
相关标签:
2条回答
  • 2021-01-27 08:01

    You can use sum or max:

    select id,max(no1),max(no2) from tab_name group by id;
    

    or

    select id,sum(no1),sum(no2) from tab_name group by id;
    
    0 讨论(0)
  • 2021-01-27 08:09

    simple group by with summation will work for you

    SELECT 
      ID,
      SUM(NO1) NO1,
      SUM(NO2) NO2
    FROM Table1
    Group by ID
    
    0 讨论(0)
提交回复
热议问题