BMS-HOSxP Community
HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Bluebird ที่ มกราคม 15, 2015, 23:47:14 PM
-
ขอช่วย Script คำนวน ระยะเวลาว่ากี่เดือน ระหว่างวันที่เกิด กับวันที่ตรวจ
ตย. วันที่ตรวจ(vstdate)-วันที่เกิด(birthdate) = จำนวนกี่เดือน
ใช้ sql ว่าอย่างไร
-
ลองแบบนี้ครับ
select v.vstdate,p.birthday,timestampdiff(year,p.birthday,v.vstdate) as count_year,
timestampdiff(month,p.birthday,v.vstdate) as count_month,timestampdiff(day,p.birthday,v.vstdate) as count_day
from vn_stat v
left outer join patient p on p.hn=v.hn
where v.hn=xxxxxxx
order by vstdate desc