Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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


pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group