SQL: Columns are same except of one content

Issue

I have the following Table:

ID           TIME            AMMOUNT

1              x                5
2              y                1
2              y                3
3              z                1
3              z                2
3              z                3

But I want it to be like this:

ID           TIME            AMMOUNT

1              x                5
2              y                4
3              z                6

How can I do this?

Solution

Use group by and sum the amount for each group:

select ID, TIME, SUM(AMMOUNT) as AMMOUNT
from table_name
group by ID, TIME

Fiddle

Answered By – Zakaria

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published