Share
Go down
avatar
Admin
Posts : 155
Join date : 2017-11-11
Age : 27
View user profilehttp://net-media.yoo7.com

merger multiple row to one in sql server

on Wed Dec 13, 2017 10:57 am
merger multiple row to one in sql server
I have a table as below,
Code:
Date                 Type     ClassA   ClassB
--------------------------------------------------
02/05/2015             A        1        
04/05/2015             B        2        -
04/05/2015             B        -        3  
05/05/2015             A        4        -
05/05/2015             B        5        -
I am trying to merge the rows as below(Required Output)
Code:
Date                 Type     ClassA   ClassB
--------------------------------------------------
02/05/2015             A        1        -
04/05/2015             B        2        3
05/05/2015             A        4        -
05/05/2015             B        5        -
In the above example, when 'Date' and 'Type' matches in 2 separate rows, I should merge the other column values to become a single row

Answers
Code:
SELECT date, type, SUM(classA), SUM(classB)
FROM yourtable
GROUP BY date, type
Back to top
Permissions in this forum:
You can reply to topics in this forum