SELECT person.pid AS 'HN'
,CONCAT(ctitle.titlename,person.fname) AS 'ชื่อ'
,person.lname AS 'นามสกุล'
,visit.visitdate AS 'วันที่มารับบริการ'
FROM person 
INNER JOIN ctitle ON person.prename = ctitle.titlecode
INNER JOIN visit ON person.pid=visit.pid
AND person.pcucodeperson=visit.pcucodeperson
WHERE person.nation <>'99'
AND person.rightcode IN ('07','8400')
AND visit.visitdate BETWEEN '2015-10-01' AND '2016-09-30'
ORDER BY visitdate;