L
L
Legitimately2019-01-03 20:55:11
SQL Server
Legitimately, 2019-01-03 20:55:11

How to merge duplicate records in a database table, while summing one of the table fields?

5c2e4c11d584e653562952.jpeg
You need to merge records with the same Pole_Id, Month, Year into one record, while adding their Count fields.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-01-03
@Legitimately

Since you haven't specified what to do with ID, you can make a grouping request. Add its result to a copy of the table and swap them. Or filter the grouping result by the number of records COUNT(*) > 1, delete by Pole_Idand add amounts.

SELECT Pole_id, Month, Year, SUM(Count)
 FROM [Table]
 GROUP BY Pole_id, Month, Year
 HAVING (COUNT(*) > 1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question