อันนี้คือ รายใหม่แต่ละเดือน นวก.ว่าโอแระ
select q2.y
,count(case when q2.month ='01' then '1' else null end )as Jan
,count(case when q2.month ='01' then '1' else null end )as Jan
,count(case when q2.month ='02' then '1' else null end )as Feb
,count(case when q2.month ='03' then '1' else null end )as Mar
,count(case when q2.month ='04' then '1' else null end )as Apr
,count(case when q2.month ='05' then '1' else null end )as May
,count(case when q2.month ='06' then '1' else null end )as Jun
,count(case when q2.month ='07' then '1' else null end )as Jul
,count(case when q2.month ='08' then '1' else null end )as Aug
,count(case when q2.month ='09' then '1' else null end )as Sep
,count(case when q2.month ='10' then '1' else null end )as Oct
,count(case when q2.month ='11' then '1' else null end )as Nov
,count(case when q2.month ='12' then '1' else null end )as "Dec"
,count(case when q2.sex = '1' then '1' else null end )as allman
,count(case when q2.sex = '2' then '1' else null end )as allwomen
,count(q2.* )as all
from
(select q1.b,q1.d,substr(q1.m,1,4) as y,substr(q1.m,6,2) as month,q1.sex as sex from
(select t_patient.patient_hn as b
,t_patient.patient_tambon as d
,t_patient.f_sex_id as sex
,min(t_visit.visit_begin_visit_time) as m
from t_diag_icd10
inner join t_visit on t_diag_icd10.diag_icd10_vn = t_visit.t_visit_id and t_visit.f_visit_status_id <> '4'
inner join t_patient on t_visit.t_patient_id = t_patient.t_patient_id and t_patient.patient_amphur = '910400'
--where substr(t_visit.visit_begin_visit_time,1,4) between '2547' and '2555'
--and ((t_diag_icd10.diag_icd10_number between 'I20' and 'I25') or ( t_diag_icd10.diag_icd10_number between 'I30' and 'I52'))
and (t_diag_icd10.diag_icd10_number between 'E10' and 'E15') --เบาหวาน
-- and (t_diag_icd10.diag_icd10_number = 'I10') --คว่มดัน
group by b,d,sex) as q1
) q2
--where q2.y ='2555'
group by q2.y
order by q2.y
--,c,d