แบบบ้าน ๆ
select * from (
select "DM" as code, sum(if(o.icd10 between "E10" and "E149",1,0)) AS cases
from ovstdiag o
where o.vstdate between '2013-10-01' and '2013-10-31'
union
select "HT" as code, sum(if(o.icd10 between "I10" and "I159",1,0)) AS Cases
from ovstdiag o
where o.vstdate between '2013-10-01' and '2013-10-31'
union
select "CVD" as code, sum(if(o.icd10 between "I20" and "I259",1,0)) AS Cases
from ovstdiag o
where o.vstdate between '2013-10-01' and '2013-10-31'
) as t
order by t.cases desc
อยากได้(กลุ่ม)โรคอะไรไปเพิ่มเอานะครับ
union
select "CVD" as code, sum(if(o.icd10 between "I20" and "I259",1,0)) AS Cases
from ovstdiag o
where o.vstdate between '2013-10-01' and '2013-10-31'