ลองเอาไปออกแบบดูครับ
ผมเขียนเอาแต่คนได้รับการคัดกรองที่อยู่ในเขตรับผิดชอบนะครับ เลือก clinic ได้ด้วย
SELECT c.hn,CONCAT(p.pname,p.fname," ",p.fname)AS ptname,p.age_y,t3.name AS TUMBON,t2.name AS AMPUR,t1.name AS CHUNGWUT,
ccs.screen_date,ccss.bmi,ccss.waist_cm,ccss.father_mother_or_parent_stroke_id,ccss.smoking,ccss.bpd_1,ccss.bps_1,ccss.bpd_1,ccss.bpd_2,
ccss.bpd_avg,ccss.bps_avg,ccss.capillary_blood_level,ccss.lipid_abnormal_id,ccss.has_heart_disease_history,
ccss.has_stroke_history,ccs.has_cerebrovascular_cormobidity,ccs.do_stroke_screen
FROM clinicmember c
LEFT OUTER JOIN clinicmember_cormobidity_screen ccs ON ccs.clinicmember_id = c.clinicmember_id
LEFT OUTER JOIN clinic_visit cv ON cv.vn = ccs.vn
LEFT OUTER JOIN clinic_visit_type cvt ON cvt.clinic_visit_type_id = cv.visit_type
LEFT OUTER JOIN clinicmember_cormobidity_stroke_screen ccss ON ccss.clinicmember_cormobidity_screen_id = ccs.clinicmember_cormobidity_screen_id
LEFT OUTER JOIN person p ON p.patient_hn = c.hn
LEFT OUTER JOIN patient pt ON pt.cid = p.cid
LEFT OUTER JOIN thaiaddress t1 on t1.addressid = concat(pt.chwpart,"0000")
LEFT OUTER JOIN thaiaddress t2 on t2.addressid = concat(pt.chwpart,pt.amppart,"00")
LEFT OUTER JOIN thaiaddress t3 on t3.addressid = concat(pt.chwpart,pt.amppart,pt.tmbpart)
WHERE ccs.screen_date BETWEEN "2013-10-01" AND "2014-03-31"
AND p.village_id<>"1"
AND ccs.do_cerebrovascular_screen="Y"
AND cv.clinic="001"
AND cv.visit_type IN("1","2")