Received: from sss2.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.9.3/8.9.3) with ESMTP id OAA49872 for ; Tue, 18 Jan 2000 14:45:32 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss2.sss.pgh.pa.us (8.9.3/8.9.3) with ESMTP id OAA01321; Tue, 18 Jan 2000 14:45:10 -0500 (EST) To: The Hermit Hacker cc: pgsql-sql@postgreSQL.org Subject: Re: [SQL] Ordering a date_part() query ... In-reply-to: References: Comments: In-reply-to The Hermit Hacker message dated "Tue, 18 Jan 2000 15:16:29 -0400" Date: Tue, 18 Jan 2000 14:45:10 -0500 Message-ID: <1318.948224710@sss.pgh.pa.us> From: Tom Lane The Hermit Hacker 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