Received: from fslc.ser.usu.edu (fslc.ser.usu.edu [129.123.28.122]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f6AJaYa66443 for ; Tue, 10 Jul 2001 15:36:34 -0400 (EDT) (envelope-from rmello@fslc.usu.edu) Received: from rmello by fslc.ser.usu.edu with local (Exim 3.22 #1 (Debian)) id 15K3J1-00076n-00; Tue, 10 Jul 2001 13:36:23 -0600 Date: Tue, 10 Jul 2001 13:36:23 -0600 From: Roberto Mello To: Graham Vickrage Cc: pgsql-sql@postgresql.org Subject: Re: Group by date_part Message-ID: <20010710133623.A27302@cc.usu.edu> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.18i X-Archive-Number: 200107/114 X-Sequence-Number: 3899 On Tue, Jul 10, 2001 at 08:04:55PM +0100, Graham Vickrage wrote: > > The statement I have only selects the count if there is at least 1 order for > a particular day, which make sense. > > I however need a count of 0 for days that don't have any. Can anyone help? > > SQL: > > SELECT date_part('day', date), count(*) > FROM client_order WHERE (date >= '01/05/01' AND date < '01/06/01') AND > status = 'Processing' > GROUP BY date_part('day', date); Didn't look very hard, but can't you just add a: CASE WHEN count(*) > 0 THEN count(*) ELSE 0 END AS count -Roberto -- +----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+ Roberto Mello - Computer Science, USU - http://www.brasileiro.net http://www.sdl.usu.edu - Space Dynamics Lab, Developer HELP! My hard drive crashed & I can't boot up!