X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9E1234753A1 for ; Sun, 2 Feb 2003 09:40:14 -0500 (EST) Received: from rtlocal.trade-india.com (mail-relay.trade-india.com [203.196.129.235]) by postgresql.org (Postfix) with SMTP id 79CD9475957 for ; Sun, 2 Feb 2003 09:40:10 -0500 (EST) Received: (qmail 16859 invoked from network); 2 Feb 2003 14:36:28 -0000 Received: from ns1.trade-india.com (HELO www.trade-india.com) (66.234.10.14) by infocom-236-129-del.trade-india.com with SMTP; 2 Feb 2003 14:36:28 -0000 Received: (qmail 8516 invoked by uid 99); 2 Feb 2003 14:39:52 -0000 Received: from 203.122.61.30 (proxying for 203.122.1.103) (SquirrelMail authenticated user mallah) by mail.trade-india.com with HTTP; Sun, 2 Feb 2003 20:09:52 +0530 (IST) Message-ID: <39392.203.122.61.30.1044196792.squirrel@mail.trade-india.com> Date: Sun, 2 Feb 2003 20:09:52 +0530 (IST) Subject: Re: Help with a query for charting From: To: In-Reply-To: References: X-Priority: 3 Importance: Normal X-MSMail-Priority: Normal Cc: X-Mailer: SquirrelMail (version 1.2.6) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/31 X-Sequence-Number: 11429 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 usin= g CASE or COALESCE. regds mallah. > I'm trying to do a query to count the number of tickets opened on each da= y 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 ; > > 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/