Re: [SQL] Ordering a date_part() query ...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: The Hermit Hacker <scrappy(at)hub(dot)org>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Ordering a date_part() query ...
Date: 2000-01-18 19:45:10
Message-ID: 1318.948224710@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

The Hermit Hacker <scrappy(at)hub(dot)org> writes:
> SELECT ( date_part('month', stat_period) || '/' ||
> date_part('day', stat_period) || '/' ||
> date_part('year', stat_period) || ' ' ||
> date_part('hour', stat_period) || ':00:00' ) as "Summary - by Day/Hour",
> sum(impressions) as impressions, sum(click_thru) as click_thru
> FROM banner_count
> GROUP BY "Summary - by Day/Hour"
> ORDER BY "Summary - by Day/Hour"::datetime;

Uh, why don't you just GROUP BY and ORDER BY stat_period?

I also wonder whether you can't find a combination of date_trunc and
datestyle that will produce the output format you want. Doing it
like the above sure seems like using the wrong tool for the job...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message The Hermit Hacker 2000-01-18 21:06:38 Re: [SQL] Ordering a date_part() query ...
Previous Message The Hermit Hacker 2000-01-18 19:16:29 Re: [SQL] Ordering a date_part() query ...