sql server - Using Where and Count from Multiply tables -


i have 2 tables

problem

columns: patient_no, encounter_date, diagnosis_1, diagnosis_2

procedure

columns: patient_no, procedure_code

i trying count number of unique clients have specific diagnosis problem table , specific procedure procedure table.

i'm using inner join on two, when run query count bigger number if counted clients specific diagnosis, think wrong.

select (select  count(diagnosis_1) problem, procedure  problem.patient_no=procedure.patient_no , problem.encounter_date between '10/1/15' , '12/31/15' , problem.diagnosis_1 in ( 'z68.53', 'z68.54', 'o99.210', 'e66.9', 'e66.3') , procedure.procedure_code in ( 'ts141', 'ts140'))   + (select  count(diagnosis_2) problem, procedure  problem.patient_no=procedure.patient_no , problem.encounter_date between '10/1/15' , '12/31/15' , problem.diagnosis_2 in ( 'z68.53', 'z68.54', 'o99.210', 'e66.9', 'e66.3') , procedure.procedure_code in ( 'ts141', 'ts140'))  

assuming you're trying count how may patient_no meet specific criteria might work you.

select count(distinct pbm.patient_no)   problem pbm     join [procedure] pdr on pbm.patient_no = pdr.patient_no  pbm.encounter_date between '10/1/15'                             ,     '12/31/15'     , (pbm.diagnosis_1 in ('z68.53','z68.54','o99.210','e66.9','e66.3')             or pbm.diagnosis_2 in ('z68.53','z68.54','o99.210','e66.9','e66.3'))     , pdr.procedure_code in ('ts141','ts140') 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -