Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 3ABFF9FC036 for ; Thu, 24 May 2007 16:46:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 28549-02 for ; Thu, 24 May 2007 16:46:02 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.246]) by postgresql.org (Postfix) with ESMTP id 7B2FB9FC047 for ; Thu, 24 May 2007 16:46:01 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c36so106563ana for ; Thu, 24 May 2007 12:45:48 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=AvW99vrUaeK9HGl/vBiQ5hS1KFdH1MrvzUw/kFFvtv+fLE9pkapGJmsZb3HQJ/uYVZ3AwaEu7SG8u5/+XGC9pQCxF3Oh2g6h04WhT/6nnPT7kB9tnJ1L/Nqz8d2Ennq1uwraj5inTnVV8e58BcrpqgFnU75/q2FtFowLHX1qDv4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=IZnbW8Zac+ZS9/89RiYBr3sIhofXAB8ifOuhu8E52he4WWjcVzQ6Hqb17vsU3mmlEVSyzSgWyAV6wFDYmoGf3nbSgupO1Z/GEfEBPfPDSD5RS/Bbo/mT2tn8voastqfsg7g0RgpOX6oDIfq9ji+241/NuxWzebHL4pMwOFG3jmE= Received: by 10.100.173.19 with SMTP id v19mr2072845ane.1180035947602; Thu, 24 May 2007 12:45:47 -0700 (PDT) Received: by 10.100.154.9 with HTTP; Thu, 24 May 2007 12:45:47 -0700 (PDT) Message-ID: Date: Thu, 24 May 2007 14:45:47 -0500 From: "=?UTF-8?Q?Rodrigo_De_Le=C3=B3n?=" To: pgsql-sql@postgresql.org, "Edward W. Rouse" Subject: Re: group by day In-Reply-To: <04c201c79e34$4e3877c0$143c520a@ntc2s.comsquared.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <04c201c79e34$4e3877c0$143c520a@ntc2s.comsquared.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/177 X-Sequence-Number: 28457 On 5/24/07, Edward W. Rouse wrote: > > > 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. > > Oh, postgres 7.4 by the way. > > > > Edward W. Rouse > > ComSquared Systems, Inc. > > 770-734-5301 SELECT TIMESTAMP, COUNT(DISTINCT(ID)) FROM AUDIT GROUP BY TIMESTAMP ORDER BY TIMESTAMP