| From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
|---|---|
| To: | Chris Campbell <ccampbell(at)cascadeds(dot)com> |
| Cc: | pgsql-novice <pgsql-novice(at)postgresql(dot)org> |
| Subject: | Re: Distinct Counts |
| Date: | 2018-04-18 22:26:35 |
| Message-ID: | CAKFQuwZGPh2-Jd=CzJ833ENLS4Z_0VToCRTYG057yOKdoE0_iw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
On Wed, Apr 18, 2018 at 3:18 PM, Chris Campbell <ccampbell(at)cascadeds(dot)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) ...
https://www.postgresql.org/docs/10/static/sql-expressions.html#SYNTAX-AGGREGATES
David J.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chris Campbell | 2018-04-19 13:34:47 | RE: Distinct Counts |
| Previous Message | Chris Campbell | 2018-04-18 22:18:48 | Distinct Counts |