Skip to content
Advertisement

Postgres totals by classification per group

for example i have an orders table with a classification column. i want to get the total per classification for each city in a state for certain identified cities, for specific date.

I have done the following, which works.

The problem is that i don’t always get the same number (16) of cities specified in the in clause.

How can i always get 16 records even if they are all zero for some

Advertisement

Answer

You need to change your join order, move the orders conditions to the left join, and use filter expressions on your count() columns.

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