Re: Help with a query for charting

From: <mallah(at)trade-india(dot)com>
To: <andrew(dot)veitch(at)blueyonder(dot)co(dot)uk>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Help with a query for charting
Date: 2003-02-02 14:39:52
Message-ID: 39392.203.122.61.30.1044196792.squirrel@mail.trade-india.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

you could keep a table with list of all possible days in a month.

left join that to the results you get from query below this will return NULL
for days where there is no data. NULL could then easily converted to 0 using CASE
or COALESCE.

regds
mallah.

> I'm trying to do a query to count the number of tickets opened on each day of a month. It'll
> always be from the 1st to the end of the month. This does it:
>
> SELECT TO_CHAR(DATE_TRUNC('day',date_opened),'DD') AS day, COUNT(*)
> FROM ticket GROUP BY DATE_TRUNC('day', date_opened)
> WHERE <date range here>;
>
> But it doesn't give me a zero for the days when no tickets were opened - which I really need
> because I want to graph the result.
>
> I could do this in the application code but that doesn't seem right.
>
> Help would be great.
>
> Andrew
>
>
> ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9'
> the postmaster

-----------------------------------------
Get your free web based email at trade-india.com.
"India's Leading B2B eMarketplace.!"
http://www.trade-india.com/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Vic Cekvenich 2003-02-02 14:47:58 help: pgSQL docs and debug
Previous Message mallah 2003-02-02 13:02:28 Re: returning table from a function