Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 61AF29FB4BD for ; Tue, 26 Jun 2007 06:02:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 92139-03 for ; Tue, 26 Jun 2007 06:01:52 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.177]) by postgresql.org (Postfix) with ESMTP id 2E2C79FB432 for ; Tue, 26 Jun 2007 06:01:56 -0300 (ADT) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu3) with ESMTP (Nemesis), id 0MKxQS-1I36vd1z24-00086w; Tue, 26 Jun 2007 11:01:54 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1I36vc-0000jY-00; Tue, 26 Jun 2007 11:01:40 +0200 Date: Tue, 26 Jun 2007 11:01:40 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Cc: Michael Landin Hostbaek Subject: Re: Where clause Message-ID: <20070626090140.GB28610@a-kretschmer.de> References: <20070626082405.GA67974@mich2.itxmarket.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070626082405.GA67974@mich2.itxmarket.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+jcHKQwC7rGEvT/2mX3P4GrZc3dtq6Ur8Ia2E XLAyhSf9b5Vuwhwfj90JqSpDD+/g19M7Pb7r8kTqKzKJcfLdOS vnp78xQhMx58Sk3cYqULeJYf9latuBo X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/214 X-Sequence-Number: 28704 am Tue, dem 26.06.2007, um 10:24:05 +0200 mailte Michael Landin Hostbaek folgendes: > Hello, > > I have a table called tracking, with a contactid varchar, click bool, > view bool and cid varchar. > > I would like to put the following into one single query if possible: > > // Number of clicks > select cid,count(distinct contactid) from tracking where click = > true group by cid; > > // Number of views > select cid,count(distinct contactid) from tracking where view = > true group by cid; > > I guess I have to put where (click = true or view = true) - and > differentiate them in the SELECT target.. ? *untested* select cid, sum(case when click = true then 1 else 0 end), sum(case when view = true then 1 else 0 end) from ... Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net