Skip to content
Advertisement

Select with IF statement on postgresql

I have a code like that:

And it returns me that error message:

I didn’t got it. As I saw on documentation, the if statement syntax appears to be used correctly

Advertisement

Answer

In Postgres, I would recommend using filter:

if is control flow logic. When working with queries, you want to learn how to think more as sets. So the idea is to filter the rows and add up the values after filtering.

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