Re: Distinct Counts - Mailing list pgsql-novice

From David G. Johnston
Subject Re: Distinct Counts
Date
Msg-id CAKFQuwZGPh2-Jd=CzJ833ENLS4Z_0VToCRTYG057yOKdoE0_iw@mail.gmail.com
Whole thread Raw
In response to Distinct Counts  (Chris Campbell <ccampbell@cascadeds.com>)
Responses RE: Distinct Counts
List pgsql-novice
On Wed, Apr 18, 2018 at 3:18 PM, Chris Campbell <ccampbell@cascadeds.com> wrote:

Select contact.accountname,

 

​​
(Select

  Count(env.fk_campaignname)

 

      FROM ds04.campaignname

      INNER JOIN ds04.envelope env ON env.fk_campaignname = campaignname.pklkey

      INNER JOIN ds04.pledge plg ON env.envelopekey = plg.fk_envelope

      WHERE plg.fk_contact = contact.contactkey

             

      ) AS reccount

               

FROM ds04.contact

WHERE contact.contactkey = 23460

GROUP BY contact.accountname, contact.contactkey

 

ORDER BY contact.accountname

 

This works fine except I’d like to change it so that the “Count()” only returns the count of unique keys.  So if this account has more than one record for a given env.fk_campaignname I only want it to count as one occurance. 

 

​(Select Count( DISTINCT  env.fk_campaignname) ... 


David J.

pgsql-novice by date:

Previous
From: Chris Campbell
Date:
Subject: Distinct Counts
Next
From: Chris Campbell
Date:
Subject: RE: Distinct Counts