RE: Distinct Counts - Mailing list pgsql-novice

From Chris Campbell
Subject RE: Distinct Counts
Date
Msg-id BYAPR11MB2677A713FD3D95780D40B97AABB50@BYAPR11MB2677.namprd11.prod.outlook.com
Whole thread Raw
In response to Re: Distinct Counts  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-novice

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.

 

 

 

Thank you David.  That did the trick.

 

Chris

 

 

 

pgsql-novice by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Distinct Counts
Next
From: "Ian Bell"
Date:
Subject: unable to read composite types from CSV files