Skip to content
Advertisement

How to get Postgres to return 0 for empty rows

I have a query which get data summarised between two dates like so:

However for dates that do not have any orders, the query returns nothing and I’d like to return 0.

I have tried with COALESCE but that doesn’t seem to do the trick?

Any suggestions?

Advertisement

Answer

Please refer to the below script.

There is one sample for your reference. Sample

I got your duplicate test cases at my side. The root cause is created_at field (datattype:timestamp), hence there are duplicate lines.

Below script is correct for your request.

Here is a sample that’s same with your side. Link

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