ผู้เขียน หัวข้อ: วันที่ตรวจ(vstdate)-วันที่เกิด(birthdate) = จำนวนกี่เดือน  (อ่าน 3334 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ Bluebird

  • Hero Member
  • *****
  • กระทู้: 1,062
  • Respect: +2
    • ดูรายละเอียด
    • โรงพยาบาลระแงะ จังหวัดนราธิวาส
ขอช่วย Script คำนวน ระยะเวลาว่ากี่เดือน ระหว่างวันที่เกิด กับวันที่ตรวจ

ตย.   วันที่ตรวจ(vstdate)-วันที่เกิด(birthdate) =  จำนวนกี่เดือน

ใช้ sql ว่าอย่างไร
นักวิชาการคอมพิวเตอร์ โรงพยาบาลระแงะ  จังหวัดนราธิวาส
www.rangaehospital.com

เริ่มใช้งานระบบ 1 ตุลาคม 2550
Server     :  HP Proliant DL180G6 RAM 16Gb. 
Replicate  : DELL PowerEdge 1800   RAM 16 Gb.
MySQL 5.5.31
OS CentOS 5 64bit
HOSxP Version : 3.59.4.27(ตาม Version ที่ออกใหม่ล่าสุด)

ออฟไลน์ golf_win

  • Hero Member
  • *****
  • กระทู้: 3,481
  • Respect: +112
    • ดูรายละเอียด
Re: วันที่ตรวจ(vstdate)-วันที่เกิด(birthdate) = จำนวนกี่เดือน
« ตอบกลับ #1 เมื่อ: มกราคม 16, 2015, 00:11:48 AM »
0
ลองแบบนี้ครับ

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
โรงพยาบาลเจ็ดเสมียน จังหวัดราชบุรี
Start 19-1-51    35 station
HOSxP  3.59.5.18 Activate License
Tel. 032-305096-7 ต่อ 118
Web. http://csmhos.thaiddns.com:8080
         http://csmhos.thaieasydns.com:8080