Sql server 我有以下问题,我正在尝试统计医疗记录员有多少次对HCV或PHA的切弗投诉 select CAST(med_rec_nbr as int) as MRN ,LM.location_name ,PE.enc_id ,PE.enc_nb

Sql server 我有以下问题,我正在尝试统计医疗记录员有多少次对HCV或PHA的切弗投诉 select CAST(med_rec_nbr as int) as MRN ,LM.location_name ,PE.enc_id ,PE.enc_nb,sql-server,tsql,Sql Server,Tsql,我有以下问题,我正在尝试统计医疗记录员有多少次对HCV或PHA的切弗投诉 select CAST(med_rec_nbr as int) as MRN ,LM.location_name ,PE.enc_id ,PE.enc_nbr ,REPLACE(convert(CHAR(25),enc_timestamp,106),'-','/') as Encounter_Date ,chiefcomplaint1 from patient_encou

我有以下问题,我正在尝试统计医疗记录员有多少次对HCV或PHA的切弗投诉
select CAST(med_rec_nbr as int) as  MRN
    ,LM.location_name
    ,PE.enc_id
    ,PE.enc_nbr
    ,REPLACE(convert(CHAR(25),enc_timestamp,106),'-','/') as Encounter_Date
    ,chiefcomplaint1    

from patient_encounter PE
JOIN master_im_ MI          on MI.enc_id=PE.enc_id and MI.person_id=PE.person_id 
JOIN patient                on patient.person_id = PE.person_id 
JOIN location_mstr LM       on LM.location_id=PE.location_id
where chiefcomplaint1 in ('HCV','PHA')
group by chiefcomplaint1 
        ,LM.location_name
        ,PE.enc_id
        ,med_rec_nbr
        ,PE.enc_nbr
        ,enc_timestamp
        ,pe.person_id
order by med_rec_nbr,location_name,enc_timestamp,enc_id,chiefcomplaint1
select CAST(med_rec_nbr as int) as  MRN
    ,LM.location_name
    ,PE.enc_id
    ,PE.enc_nbr
    ,REPLACE(convert(CHAR(25),enc_timestamp,106),'-','/') as Encounter_Date
    ,chiefcomplaint1  
    ,COUNT(*) AS Num_Complains  

from patient_encounter PE
JOIN master_im_ MI          on MI.enc_id=PE.enc_id and MI.person_id=PE.person_id 
JOIN patient                on patient.person_id = PE.person_id 
JOIN location_mstr LM       on LM.location_id=PE.location_id
where chiefcomplaint1 in ('HCV','PHA')
group by CAST(med_rec_nbr as int) 
        ,LM.location_name
        ,PE.enc_id
        ,PE.enc_nbr
        ,REPLACE(convert(CHAR(25),enc_timestamp,106),'-','/')
        ,chiefcomplaint1 
order by med_rec_nbr,location_name,enc_timestamp,enc_id,chiefcomplaint1