Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 6C6879FB8A9 for ; Tue, 26 Jun 2007 07:31:15 -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 63127-04 for ; Tue, 26 Jun 2007 07:31:11 -0300 (ADT) X-Greylist: delayed 03:11:51.271265 by SQLgrey-1.7.4 Received: from smadev.internal.net (host3.dynacom.ondsl.gr [62.103.35.211]) by postgresql.org (Postfix) with ESMTP id B91409FB89E for ; Tue, 26 Jun 2007 07:31:11 -0300 (ADT) Received: from smadev.internal.net (localhost [127.0.0.1]) by smadev.internal.net (8.13.6/8.13.6) with ESMTP id l5QAV9bp064486; Tue, 26 Jun 2007 13:31:09 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) Received: from localhost (localhost [[UNIX: localhost]]) by smadev.internal.net (8.13.6/8.13.6/Submit) id l5QAV44J064485; Tue, 26 Jun 2007 13:31:04 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: Michael Landin Hostbaek , "A. Kretschmer" , pgsql-sql@postgresql.org Subject: Re: Where clause Date: Tue, 26 Jun 2007 13:31:03 +0300 User-Agent: KMail/1.9.3 References: <20070626082405.GA67974@mich2.itxmarket.com> <20070626090140.GB28610@a-kretschmer.de> <20070626094453.GH67974@mich2.itxmarket.com> In-Reply-To: <20070626094453.GH67974@mich2.itxmarket.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200706261331.04033.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/216 X-Sequence-Number: 28706 =D3=F4=E9=F2 =D4=F1=DF=F4=E7 26 =C9=EF=FD=ED=E9=EF=F2 2007 12:44, =EF/=E7 M= ichael Landin Hostbaek =DD=E3=F1=E1=F8=E5: > A. Kretschmer (andreas.kretschmer) writes: > > *untested* > > > > select cid, sum(case when click =3D true then 1 else 0 end), sum(case w= hen > > view =3D true then 1 else 0 end) from ... > > Thanks, but I need the DISTINCT contactid - I don't want the same > contactid counted twice. > Something like SELECT distinct cid,(select count(distinct t1.contactid) from tracking t1=20 where t1.view and t1.cid=3Dtglob.cid) as countviews,(select count(distinct= =20 t2.contactid) from tracking t2 where t2.click and t2.cid=3Dtglob.cid) as=20 countclicks from tracking tglob; ? > Mike > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend =2D-=20 Achilleas Mantzios