Received: from thelab.hub.org (nat200.60.mpoweredpc.net [142.177.200.60]) by hub.org (8.9.3/8.9.3) with ESMTP id OAA40630 for ; Tue, 18 Jan 2000 14:16:29 -0500 (EST) (envelope-from scrappy@hub.org) Received: from localhost (scrappy@localhost) by thelab.hub.org (8.9.3/8.9.1) with ESMTP id PAA25090; Tue, 18 Jan 2000 15:16:29 -0400 (AST) (envelope-from scrappy@hub.org) X-Authentication-Warning: thelab.hub.org: scrappy owned process doing -bs Date: Tue, 18 Jan 2000 15:16:29 -0400 (AST) From: The Hermit Hacker To: Mark Volpe cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Ordering a date_part() query ... In-Reply-To: <3884B5BA.C1155D45@epamail.epa.gov> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Had thought about that one: 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; results in: ERROR: attribute 'Summary - by Day/Hour' not found But, that gave me an idea... SELECT ( date_part('month', stat_period) || '/' || date_part('day', stat_period) || '/' || date_part('year', stat_period) || ' ' || date_part('hour', stat_period) || ':00:00' )::datetime as day, sum(impressions) as impressions, sum(click_thru) as click_thru FROM banner_count GROUP BY day; CASTing the results gives me what I want, and gives cleaner lookign results then what I had :) Summary - by Day/Hour |impressions|click_thru ----------------------------+-----------+---------- Mon Jan 17 23:00:00 2000 EST| 63| 1 Tue Jan 18 00:00:00 2000 EST| 151| 0 Tue Jan 18 01:00:00 2000 EST| 89| 0 Tue Jan 18 02:00:00 2000 EST| 112| 0 Tue Jan 18 03:00:00 2000 EST| 178| 0 Tue Jan 18 04:00:00 2000 EST| 184| 0 Tue Jan 18 05:00:00 2000 EST| 133| 0 Tue Jan 18 06:00:00 2000 EST| 119| 0 Tue Jan 18 07:00:00 2000 EST| 148| 0 Tue Jan 18 08:00:00 2000 EST| 224| 0 Tue Jan 18 09:00:00 2000 EST| 272| 0 Tue Jan 18 10:00:00 2000 EST| 348| 4 Tue Jan 18 11:00:00 2000 EST| 804| 1 Tue Jan 18 12:00:00 2000 EST| 632| 1 Tue Jan 18 13:00:00 2000 EST| 1200| 0 Tue Jan 18 14:00:00 2000 EST| 110| 0 On Tue, 18 Jan 2000, Mark Volpe wrote: > INSERT INTO my_brain VALUES ('clue') :-) > > Whoops, Bruce's response reminded me, > what I meant to say was > ORDER BY "Summary - by Day/Hour"::datetime > > Mark > > The Hermit Hacker wrote: > > > > 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"; > > > Marc G. Fournier ICQ#7615664 IRC Nick: Scrappy Systems Administrator @ hub.org primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org