SELECT DISTINCT o.visit_id ,o.hn, o.unit_reg, a.ap_date regdate, a1.ap_date, a1.ap_memo,
o.staff_id , CONCAT(trim(p1.fname), ' ' , p1.lname) staff_name
FROM appoints a
LEFT JOIN opd_visits o ON a.ap_date = date(o.REG_DATETIME)
INNER JOIN cid_hn c ON c.hn = o.hn
INNER JOIN population p ON p.cid = c.cid
LEFT JOIN appoints a1 ON a1.hn = o.hn
INNER JOIN staff s ON s.staff_id = a1.staff_id
INNER JOIN population p1 ON p1.cid = s.cid
WHERE o.REG_DATETIME BETWEEN CURDATE() AND NOW()
AND a1.ap_date > a.ap_date
AND o.hn = '017192'
GROUP BY o.visit_id
ไม่มีความคิดเห็น:
แสดงความคิดเห็น