SELECT
CONCAT(ctitle.titlename,person.fname,' ',person.lname)AS 'ชื่อ-สกุล',
GetAgeYearNum(person.birth,CURRENT_DATE)AS 'อายุ',
CONCAT(person.hnomoi,' ','หมู่',person.mumoi) AS 'ที่อยู่',
CONCAT(MAX(CASE WHEN MONTH(visit.visitdate)=10 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) ,'/',
MAX(CASE WHEN MONTH(visit.visitdate)=10 THEN SUBSTR(visit.pressure,INSTR(visit.pressure,'/')+1,LENGTH(visit.pressure)-INSTR(visit.pressure,'/')) ELSE '' END) ) AS 'ต.ค.',
CONCAT(MAX(CASE WHEN MONTH(visit.visitdate)=11 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) ,'/',
MAX(CASE WHEN MONTH(visit.visitdate)=11 THEN SUBSTR(visit.pressure,INSTR(visit.pressure,'/')+1,LENGTH(visit.pressure)-INSTR(visit.pressure,'/')) ELSE '' END) ) AS 'พ.ย.',
CONCAT(MAX(CASE WHEN MONTH(visit.visitdate)=12 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) ,'/',
MAX(CASE WHEN MONTH(visit.visitdate)=12 THEN SUBSTR(visit.pressure,INSTR(visit.pressure,'/')+1,LENGTH(visit.pressure)-INSTR(visit.pressure,'/')) ELSE '' END) ) AS 'ธ.ค.',
CONCAT(MAX(CASE WHEN MONTH(visit.visitdate)=01 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) ,'/',
MAX(CASE WHEN MONTH(visit.visitdate)=01 THEN SUBSTR(visit.pressure,INSTR(visit.pressure,'/')+1,LENGTH(visit.pressure)-INSTR(visit.pressure,'/')) ELSE '' END) ) AS 'ม.ค.',
CONCAT(MAX(CASE WHEN MONTH(visit.visitdate)=02 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) ,'/',
MAX(CASE WHEN MONTH(visit.visitdate)=0 THEN SUBSTR(visit.pressure,INSTR(visit.pressure,'/')+1,LENGTH(visit.pressure)-INSTR(visit.pressure,'/')) ELSE '' END) ) AS 'ก.พ.',
MAX(CASE WHEN MONTH(visit.visitdate)=3 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) AS 'มี.ค.',
MAX(CASE WHEN MONTH(visit.visitdate)=4 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) AS 'เม.ย.',
MAX(CASE WHEN MONTH(visit.visitdate)=5 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) AS 'พ.ค.',
MAX(CASE WHEN MONTH(visit.visitdate)=6 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) AS 'มิ.ย.',
MAX(CASE WHEN MONTH(visit.visitdate)=7 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) AS 'ก.ค.',
MAX(CASE WHEN MONTH(visit.visitdate)=8 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) AS 'ส.ค.',
MAX(CASE WHEN MONTH(visit.visitdate)=9 THEN SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) ELSE '' END) AS 'ก.ย.'
FROM person
INNER JOIN ctitle ON person.prename = ctitle.titlecode
INNER JOIN personchronic ON person.pid=personchronic.pid
INNER JOIN cdisease ON personchronic.chroniccode=cdisease.diseasecode
INNER JOIN house ON person.hcode = house.hcode AND person.pcucodeperson = house.pcucode
INNER JOIN visit ON person.pcucodeperson = visit.pcucodeperson
AND person.pid = visit.pid
INNER JOIN village ON house.villcode = village.villcode AND house.pcucode = village.pcucode
WHERE visit.visitdate BETWEEN '2014-10-01' AND '2015-09-30'
AND SUBSTRING(house.villcode,7,2)<> '00' AND SUBSTR(visit.pressure,1,INSTR(visit.pressure,'/')-1) BETWEEN 120 AND 139 
AND SUBSTR(visit.pressure,INSTR(visit.pressure,'/')+1,LENGTH(visit.pressure)-INSTR(visit.pressure,'/')) BETWEEN 79 AND 89
AND personchronic.chroniccode BETWEEN 'I10' AND 'I15.9'
GROUP BY personchronic.pid
ORDER BY village.villno;