My query:
with cte as (
select client_id,COUNT(patient_id) PatientCount from
(
select client_id,patient_id
from F_ACCESSION_DAILY
group by CLIENT_ID,PATIENT_ID
having COUNT(ACCESSION_ID)=2
) a
group by CLIENT_ID
)
works, but is not so useful to me. because although i can JOIN easily on this query, I will actually need to repeat this WITH
statement many times because i need to be able to differentiate between:
having count(Accession_id)=2
and
having count(Accession_id)=3
and
having count(accession_id)=4
and so on until around 100
i was thinking to do something more like this:
select distinct client_id, patient_id, count(*) over (partition by client_id, patient_id,accession_id) patientcount
from f_accession_daily
but i am stuck!
i was wondering if you can point me into the right direction on how to convert the initial query into something more useable when having count(Accession)=many different values?
thanks so much for your guidance.