Jeg tror, at date_trunc
funktion kan være din ven (se postgres-dokumenter a> ). Du ville gøre noget som dette, tror jeg:
select
COUNT(ID) as Total,
COUNT(CASE WHEN createddate between date_trunc('month', now()) AND now() THEN AG.ID END) as ThisMonth,
COUNT(CASE WHEN createddate between date_trunc('month', now()) - interval '1 month' AND date_trunc('month', now()) - interval '1 day' THEN AG.ID END) as LastMonth,
osv...