ลองดู ถ้าไม่ใช่คำตอบก็มองผ่านไปละกัน
select c.hn,concat(p.pname,p.fname," ",p.lname) as patient_name ,count(c.clinic) as cc,
YEAR( FROM_DAYS( DATEDIFF( NOW( ) , p.birthday ))) as age,
concat("บ้านเลขที่ " ,p.addrpart," หมู่ที่ ", p.moopart," ต. ", d.district ," อ. ", d.amphur," จ. ", d.province) as address, c.lastvisit AS date_visit
from clinicmember c,patient p, dbaddress d
where c.hn = p.hn and (c.clinic in (select sys_value from sys_var where sys_name = "ht_clinic_code")
or c.clinic in (select sys_value from sys_var where sys_name = "dm_clinic_code") )
and CONCAT(p.chwpart,p.amppart,p.tmbpart) = d.iddistrict
AND CONCAT(p.chwpart,p.amppart) = d.idamphur
AND p.chwpart = d.idprovince
group by c.hn ,p.pname,p.fname,p.lname
having count(c.clinic)>1