I'm doing a search on some tables, I want to calculate the result of a table, and when it does not have data on the date I set, I want to show the number zero.
SELECT
l.key as "Licença",
coalesce(sum(c."customersAmount"), 0) as "Comsumo dos ultimos 30 dias"
FROM
consumptions c
LEFT JOIN licenses l on c."licenseKey"=l.key
WHERE
c."consumedAt" >= current_date - interval '30' day AND
l.label LIKE '%Casa%'
GROUP BY
l.key
ORDER BY
l.key ASC;
The lkey that has no consumption, I want to display the number zero (0).
how can I do this ? thank you