RE: Distinct Counts

Поиск
Список
Период
Сортировка
От Chris Campbell
Тема RE: Distinct Counts
Дата
Msg-id BYAPR11MB2677A713FD3D95780D40B97AABB50@BYAPR11MB2677.namprd11.prod.outlook.com
обсуждение исходный текст
Ответ на Re: Distinct Counts  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Distinct Counts
Следующее
От: "Ian Bell"
Дата:
Сообщение: unable to read composite types from CSV files