Re: Distinct Counts

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Distinct Counts
Дата
Msg-id CAKFQuwZGPh2-Jd=CzJ833ENLS4Z_0VToCRTYG057yOKdoE0_iw@mail.gmail.com
обсуждение исходный текст
Ответ на Distinct Counts  (Chris Campbell <ccampbell@cascadeds.com>)
Ответы RE: Distinct Counts  (Chris Campbell <ccampbell@cascadeds.com>)
Список 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 по дате отправления:

Предыдущее
От: Chris Campbell
Дата:
Сообщение: Distinct Counts
Следующее
От: Chris Campbell
Дата:
Сообщение: RE: Distinct Counts