Skip to content
Advertisement

SQL query using Sum() and count() functions

I’m trying to query in PostgresQL using the SUM function to get the total of 3 different row types (Root, Dynamic, Test). I used the Sum() function for the first attempt and the Count() function for the second attempt; both didn’t work sadly. I expect a syntax error (since I’m a beginner at using SQL), but I’m not sure what it is and how to fix it!

1st attempt with the Sum() function:

2nd attempt with the Count() function:

Can I please get help with this? Thank you 🙂

Advertisement

Answer

Consider using the filter syntax to aggreagate functions, which is standard SQL and that Postgres supports:

If you were to write this without the filter syntax (as in your first attempt), a portable syntax is:

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