Re: group by function, make SQL cleaner?

From: Stefan Becker <stefan(at)yukonho(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: group by function, make SQL cleaner?
Date: 2006-03-16 06:46:27
Message-ID: 200603160746.27272.stefan@yukonho.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

this should work,
#
SELECT date_trunc('day',endtime),count(*)
FROM eg_event where endtime >= '2006-02-01' and endtime < '2006-03-01'
GROUP BY 1
ORDER BY 1;

best regards,

Stefan

Am Donnerstag, 16. März 2006 06:18 schrieb Bryce Nesbitt:
> I've got a working query:
>
> stage=# SELECT date_trunc('day',endtime),count(*)
> FROM eg_event where endtime >= '2006-02-01' and endtime < '2006-03-01'
> GROUP BY date_trunc('day',endtime)
> ORDER BY date_trunc('day',endtime);
>
> date_trunc | count
> ---------------------+-------
> 2006-02-01 00:00:00 | 253
> 2006-02-02 00:00:00 | 245
> 2006-02-03 00:00:00 | 231
> 2006-02-04 00:00:00 | 313
> 2006-02-05 00:00:00 | 285
> 2006-02-06 00:00:00 | 194
> 2006-02-07 00:00:00 | 229
> 2006-02-08 00:00:00 | 239
> 2006-02-09 00:00:00 | 250
> 2006-02-10 00:00:00 | 245
> 2006-02-11 00:00:00 | 275
>
> Is there a way to eliminate the ugly repeated use of
> date_trunc('day',endtime)?
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
email: stefan(at)yukonho(dot)de
tel : +49 (0)6232-497631
http://www.yukonho.de

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message rcolmegna@tiscali.it 2006-03-16 14:55:51 schema inspection
Previous Message Tom Lane 2006-03-16 06:04:58 Re: group by function, make SQL cleaner?