Skip to content
Advertisement

Sum with SQL depending on the value of a column

I have 3 columns : year, price, and day_type.

I want to keep only the lines where day_type = 1 or 2, but add to these lines the value when day_type = 0.

Expected Result :

How can I do that?

Advertisement

Answer

You can use a join:

This uses left join in case one of the years does not have a 0 price.

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