1

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.

4

1 に答える 1

1

Something like...?

   select client_id,accessioncount,COUNT(patient_id) PatientCount from 
    ( 
        select client_id,patient_id, count(accession_id) as accessioncount
        from F_ACCESSION_DAILY 
        group by CLIENT_ID,PATIENT_ID 
    ) a 
    group by CLIENT_ID,accessioncount
于 2012-10-19T07:58:10.210 に答える