SELECT
SUM( if(year(visit.visitdate)+543 =2550,1,0) ) AS `2550`,
SUM( if(year(visit.visitdate)+543 =2551,1,0) ) AS `2551`,
SUM( if(year(visit.visitdate)+543 =2552,1,0) ) AS `2552`,
SUM( if(year(visit.visitdate)+543 =2553,1,0) ) AS `2553`,
SUM( if(year(visit.visitdate)+543 =2554,1,0) ) AS `2554`,
SUM( if(year(visit.visitdate)+543 =2555,1,0) ) AS `2555`,
SUM( if(year(visit.visitdate)+543=2556,1,0) ) AS `2556`,
SUM( if(year(visit.visitdate)+543 =2557,1,0) ) AS `2557`,
if(LENGTH(person.mumoi)=1,CONCAT("0",person.mumoi),person.mumoi) as "หมู่ที่"
FROM
visit
INNER JOIN visitdiag ON visit.visitno = visitdiag.visitno
INNER JOIN person ON visit.pid = person.pid
#WHERE
#visitdiag.diagcode not LIKE '%z%' and visitdiag.diagcode not LIKE '%u%'
WHERE
visitdiag.diagcode NOT LIKE '%u%' AND visitdiag.diagcode NOT LIKE '%z%'

GROUP BY หมู่ที่;