X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 470EB9DC808 for ; Thu, 16 Mar 2006 01:18:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81363-07 for ; Thu, 16 Mar 2006 01:18:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from outbound.internet-mail-service.net (outbound6.internet-mail-service.net [216.240.47.197]) by postgresql.org (Postfix) with ESMTP id 5C3C49DC805 for ; Thu, 16 Mar 2006 01:18:48 -0400 (AST) Received: from idiom.com (idiom.com [216.240.32.1]) by outbound.internet-mail-service.net (Postfix) with ESMTP id 740A5240C36 for ; Wed, 15 Mar 2006 21:18:47 -0800 (PST) Received: from [192.168.1.109] (adsl-69-107-132-69.dsl.pltn13.pacbell.net [69.107.132.69]) by idiom.com (8.12.11/8.12.11) with ESMTP id k2G5IlhJ050441 for ; Wed, 15 Mar 2006 21:18:47 -0800 (PST) (envelope-from bryce1@obviously.com) Message-ID: <4418F52F.4070804@obviously.com> Date: Wed, 15 Mar 2006 21:18:40 -0800 From: Bryce Nesbitt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: group by function, make SQL cleaner? Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.143 required=5 tests=[AWL=0.143] X-Spam-Score: 0.143 X-Spam-Level: X-Archive-Number: 200603/227 X-Sequence-Number: 24573 I've got a working query: stage=# SELECT date_trunc('day',endtime),count(*) FROM eg_event where endtime >= '2006-02-01' and endtime < '2006-03-01' GROUP BY date_trunc('day',endtime) ORDER BY date_trunc('day',endtime); date_trunc | count ---------------------+------- 2006-02-01 00:00:00 | 253 2006-02-02 00:00:00 | 245 2006-02-03 00:00:00 | 231 2006-02-04 00:00:00 | 313 2006-02-05 00:00:00 | 285 2006-02-06 00:00:00 | 194 2006-02-07 00:00:00 | 229 2006-02-08 00:00:00 | 239 2006-02-09 00:00:00 | 250 2006-02-10 00:00:00 | 245 2006-02-11 00:00:00 | 275 Is there a way to eliminate the ugly repeated use of date_trunc('day',endtime)?