Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id E07601337C08 for ; Fri, 11 Feb 2011 14:51:53 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 06125-04 for ; Fri, 11 Feb 2011 18:51:47 +0000 (UTC) X-Greylist: delayed 00:05:25.822451 by SQLgrey-1.7.6 Received: from exprod6og112.obsmtp.com (exprod6og112.obsmtp.com [64.18.1.29]) by mail.postgresql.org (Postfix) with SMTP id 0E07A1337C00 for ; Fri, 11 Feb 2011 14:51:45 -0400 (AST) Received: from source ([66.152.196.38]) (using TLSv1) by exprod6ob112.postini.com ([64.18.5.12]) with SMTP ID DSNKTVWFQT/c9IZKtxOeSoQN4T/2UfNhtP4t@postini.com; Fri, 11 Feb 2011 10:51:46 PST Received: from EXCHMAIL.bzzagent.lan ([172.16.92.56]) by EXCHCAS.bzzagent.lan ([192.168.1.22]) with mapi; Fri, 11 Feb 2011 13:46:17 -0500 From: Aaron Burnett To: "pgsql-sql@postgresql.org" Date: Fri, 11 Feb 2011 13:46:15 -0500 Subject: Drawing a blank on some SQL Thread-Topic: Drawing a blank on some SQL Thread-Index: AcvKG/X7OQjOULpTn0qTfyMto5ruiQ== Message-ID: Accept-Language: en-US Content-Language: en X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.2 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201102/52 X-Sequence-Number: 35128 Hi, I'm just drawing a blank entirely today and would appreciate some help on this. The long and short; there are 12 distinct activities that need to be querie= d on a weekly basis: SELECT count(activity_id), activity_id FROM foo_activity=20 WHERE created >=3D '01/01/2011' and created < '01/08/2011' GROUP BY 2=20 ORDER BY 2; It gives me this answer, which is correct: count | activity_id -------+--------------------- 1502 | 1 11 | 2 2 | 3 815 | 4 4331 | 7 30 | 9 1950 | 10 7 | 11 67 | 12 But what I need to see is if there are no activities for the particular activity_id that week, that it lists the count as 0 and lists the activity_id associated like this: count | activity_id -------+--------------------- 1502 | 1 11 | 2 2 | 3 815 | 4 0 | 5 0 | 6 4331 | 7 0 | 8 30 | 9 1950 | 10 7 | 11 67 | 12 Thanking you in advance for any help on this. The caffiene seems to be not working well today. Aaron