Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B12FD9FBFC1 for ; Thu, 24 May 2007 16:42:49 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 92112-07 for ; Thu, 24 May 2007 16:42:46 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.187]) by postgresql.org (Postfix) with ESMTP id CEECF9FB92B for ; Thu, 24 May 2007 16:42:45 -0300 (ADT) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu1) with ESMTP (Nemesis), id 0MKwpI-1HrJCt2kdy-00041n; Thu, 24 May 2007 21:42:44 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1HrJCs-0005Vi-00 for pgsql-sql@postgresql.org; Thu, 24 May 2007 21:42:42 +0200 Date: Thu, 24 May 2007 21:42:42 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: group by day Message-ID: <20070524194242.GA21054@a-kretschmer.de> References: <04c201c79e34$4e3877c0$143c520a@ntc2s.comsquared.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <04c201c79e34$4e3877c0$143c520a@ntc2s.comsquared.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1+qcVgQWCkDYdXEJUazOA6dTKjcBAsXAUu22If eibYkfOLrZKLQqHcyqQhoRQdGRjtRdxNjNDj8NzPACz/SlUbt/ qHDy4oPZvhR/yysO9NPuKUozvHQrSWk X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/176 X-Sequence-Number: 28456 am Thu, dem 24.05.2007, um 14:49:47 -0400 mailte Edward W. Rouse folgendes: > I have an audit table that I am trying to get a count of the number of distinct > entries per day by the external table key field. I can do a > > select count(distinct(id)) from audit where timestamp >= '01-may-2007' > > and get a total count. What I need is a way to group on each day and get a > count per day such that the result would be something like > > date count > 01-may-2007 107 > 02-may-2007 215 > 03-may-2007 96 > 04-may-2007 0 > > > I would prefer the 0 entries be included but can live without them. Thanks. You are searching for GROUP BY. A simple example: test=*# select * from foo; ts | val ---------------------+----- 2007-05-01 08:00:00 | 10 2007-05-01 08:00:00 | 20 2007-05-02 10:00:00 | 20 2007-05-02 11:00:00 | 30 (4 rows) Time: 1.079 ms test=*# select ts::date, sum(val) from foo group by 1; ts | sum ------------+----- 2007-05-02 | 50 2007-05-01 | 30 (2 rows) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net