Re: Where clause

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: Michael Landin Hostbaek <mich(at)the-lab(dot)org>, "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Where clause
Date: 2007-06-26 10:31:03
Message-ID: 200706261331.04033.achill@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Στις Τρίτη 26 Ιούνιος 2007 12:44, ο/η Michael Landin Hostbaek έγραψε:
> A. Kretschmer (andreas.kretschmer) writes:
> > *untested*
> >
> > select cid, sum(case when click = true then 1 else 0 end), sum(case when
> > view = 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
where t1.view and t1.cid=tglob.cid) as countviews,(select count(distinct
t2.contactid) from tracking t2 where t2.click and t2.cid=tglob.cid) as
countclicks from tracking tglob;

?
> Mike
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

--
Achilleas Mantzios

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2007-06-26 10:45:21 Re: Where clause
Previous Message Michael Landin Hostbaek 2007-06-26 09:44:53 Re: Where clause