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

From: "omid omoomi" <oomoomi(at)hotmail(dot)com>
To: scrappy(at)hub(dot)org
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Ordering a date_part() query ...
Date: 2000-01-18 10:48:22
Message-ID: 20000118184822.21055.qmail@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,
Try some thing like this ( using order by clause ):
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
Date_part('day', stat_period ) , Date_part('hour',stat_period) ;

Hope that helps,
regards.
Omid Omoomi

>From: The Hermit Hacker <scrappy(at)hub(dot)org>
>To: pgsql-sql(at)postgresql(dot)org
>Subject: [SQL] Ordering a date_part() query ...
>Date: Tue, 18 Jan 2000 13:20:08 -0400 (AST)
>
>
>I have a query that looks like:
>
>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";
>
>
>Works great, except that the output looks like:
>
>Summary - by Day/Hour|impressions|click_thru
>---------------------+-----------+----------
>1/17/2000 23:00:00 | 63| 1
>1/18/2000 0:00:00 | 151| 0
>1/18/2000 10:00:00 | 348| 4
>1/18/2000 11:00:00 | 804| 1
>1/18/2000 12:00:00 | 180| 1
>1/18/2000 1:00:00 | 89| 0
>1/18/2000 2:00:00 | 112| 0
>1/18/2000 3:00:00 | 178| 0
>1/18/2000 4:00:00 | 184| 0
>1/18/2000 5:00:00 | 133| 0
>1/18/2000 6:00:00 | 119| 0
>1/18/2000 7:00:00 | 148| 0
>1/18/2000 8:00:00 | 224| 0
>1/18/2000 9:00:00 | 272| 0
>
>Notice the 10/11/12/etc hour stats come before the 1am stats?
>
>So its sorting okay on the date, but I need to get it to d it on the time
>as well..
>
>I'm still playing with it, but if someone can suggest a means of doing
>this, I'm all ears :)
>
>Thanks...
>
>Marc G. Fournier ICQ#7615664 IRC Nick:
>Scrappy
>Systems Administrator @ hub.org
>primary: scrappy(at)hub(dot)org secondary:
>scrappy(at){freebsd|postgresql}.org
>
>
>************
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Browse pgsql-sql by date

  From Date Subject
Next Message Marc Tardif 2000-01-18 14:04:48 char(19) to varchar(32)
Previous Message omid omoomi 2000-01-18 10:48:11 Re: [SQL] Ordering a date_part() query ...