Skip to content
Advertisement

SQL: Add multiple where clauses in a single query

I want to run an SQL query from Node.js. I am currently showing the total number of projects that have a specific status in each of the 4 quarters. What I want to do now is show the same result but while adding one more condition i.e, Fiscal Year.

Here’s my code for the 4 quarters:

This prints output in 4 different rows which is exactly what I want. But, when I add one more condition then it does execute but only one row gets printed since the projects in the rest of the 3 quarters for that year do not exist. I want to somehow print 4 different rows for quarters for every Fiscal Year. The query should print 0 in the row if no projects exist for that quarter in a year. How can I do that? My SQL is not that strong, it would be great if someone can help me out.

Advertisement

Answer

Can you tell me programmatically how to do that?

Maybe SUMs must be wrapped with COALESCE() for to replace NULLs to zeros.

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