pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: mallah@trade-india.com
To: andrew.veitch@blueyonder.co.uk
Cc: pgsql-sql@postgresql.org
Subject: Re: Help with a query for charting
Date: Sun, 2 Feb 2003 20:09:52 +0530 (IST)
Message-ID: <39392.203.122.61.30.1044196792.squirrel@mail.trade-india.com> (raw)
In-Reply-To: <BA606925.884E%andrew.veitch@blueyonder.co.uk>
References: <BA606925.884E%andrew.veitch@blueyonder.co.uk>



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/





view thread (3+ messages)  latest in thread

Message-ID: <39392.203.122.61.30.1044196792.squirrel@mail.trade-india.com>
Permalink:  ../39392.203.122.61.30.1044196792.squirrel@mail.trade-india.com/
Also on:    postgresql.org/message-id/39392.203.122.61.30.1044196792.squirrel@mail.trade-india.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mallah@trade-india.com, andrew.veitch@blueyonder.co.uk
  Subject: Re: Help with a query for charting
  In-Reply-To: <39392.203.122.61.30.1044196792.squirrel@mail.trade-india.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox