Skip to content
Advertisement

Summing duplicates rows

I have a database with more than 300 duplicates that look like this:

JavaScript

I want that for each duplicate shipment_id only original_cost gets added together and rates remain as they are.

JavaScript

like for these duplicates: it should look something like this:

JavaScript

is there any way to do this?

Advertisement

Answer

Group by the duplicate values (['shipment_id', 'rate']) and use transform on the “original_cost” column to calculate the sum:

JavaScript

Example input:

JavaScript

Example output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement