SELECT
case when month(visitlabcancer.datecheck)=1 then 'มกราคม'
when month(visitlabcancer.datecheck)=2 then 'กุมภาพันธ์'
when month(visitlabcancer.datecheck)=3 then 'มีนาคม'
when month(visitlabcancer.datecheck)=4 then 'เมษายน'
when month(visitlabcancer.datecheck)=5 then 'พฤษภาคม'
when month(visitlabcancer.datecheck)=6 then 'มิถุนายน'
when month(visitlabcancer.datecheck)=7 then 'กรกฎาคม'
when month(visitlabcancer.datecheck)=8 then 'สิงหาคม'
when month(visitlabcancer.datecheck)=9 then 'กันยายน'
when month(visitlabcancer.datecheck)=10 then 'ตุลาคม'
when month(visitlabcancer.datecheck)=11 then 'พฤศจิกายน'
when month(visitlabcancer.datecheck)=12 then 'ธันวาคม' else null end as 'GroupMonth',
year(visitlabcancer.datecheck) as 'ปี',
sum(case when month(visitlabcancer.datecheck) and visitlabcancer.typecancer= '1' then 1 else null end) as 'คัดกรองเต้านม',
sum(case when month(visitlabcancer.datecheck) and visitlabcancer.typecancer= '1'and visitlabcancer.result = '1' then 1 else null end) as 'พบผิดปกติ',
sum(case when month(visitlabcancer.datecheck) and visitlabcancer.typecancer= '1'and visitlabcancer.result = '2' then 1 else null end) as 'พบเซลล์มะเร็ง',
sum(case when month(visitlabcancer.datecheck) and visitlabcancer.typecancer= '2' then 1 else null end) as 'Papsmear',
sum(case when month(visitlabcancer.datecheck) and visitlabcancer.typecancer= '2'and visitlabcancer.result = '1' then 1 else null end) as 'ผิดปกติ CAT II',
sum(case when month(visitlabcancer.datecheck) and visitlabcancer.typecancer= '2'and visitlabcancer.result = '2' then 1 else null end) as 'ผิดปกติ CAT III,IV',
sum(case when month(visitlabcancer.datecheck) and visitlabcancer.typecancer= '2'and visitlabcancer.result = '9' then 1 else null end) as 'ผิดปกติไม่ใช่มะเร็ง'
FROM visitlabcancer
INNER JOIN person ON visitlabcancer.pcucodeperson = person.pcucodeperson AND visitlabcancer.pid = person.pid
where getAgeYearNum(birth,visitlabcancer.datecheck) between '30' and '60'
and sex = '2'
and visitlabcancer.datecheck between '2013-10-01' and '2014-09-30'
and person.typelive in ('1','3')
and person.dischargetype != '1'
group by GroupMonth
#order by 'ปี' ASC;