Re: Group by date_part

From: Roberto Mello <rmello(at)cc(dot)usu(dot)edu>
To: Graham Vickrage <graham(at)digitalplanit(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Group by date_part
Date: 2001-07-10 19:36:23
Message-ID: 20010710133623.A27302@cc.usu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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!

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kristis Makris 2001-07-10 20:34:54 ERROR: Procedures cannot take more than 16 arguments
Previous Message Andre Schnabel 2001-07-10 19:35:56 Re: Problems with PG_DUMP and restore