BMS-HOSxP Community
HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: Guitar-hero ที่ กันยายน 20, 2010, 16:32:14 PM
-
คือผมต้องการดึงข้อมูลคนไข้ โดยสามารถเลือกตามกลุ่มอายุได้ โดยคำสั่ง sql ที่ผมเขียนประมาณนี้
select pt.*,ov.*
from vn_stat ov ,patient pt ,ovst ovst
where ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2010-09-01" and "2010-09-10" and ov.hn=pt.hn
and ov.age_y>= 0
and ov.age_y<= 1
and ov.spclty="01"
ซึ่งจริงๆแล้ว ผมต้องการให้มันแสดงข้อมูลอายุ ตามเงือนไขดังต่อไปนี้
0-1 ปี
1 ปี 1 เดือน - 3 ปี
3 ปี 1 เดือน -5 ปี 11 เดือน
6 ปี - 12 ปี 11 เดือน
13 ปี -18 ปี
จะใช้ sql ยังไงครับ ถึงจะกำหนด เงื่อนไขระดับ 1 ปี 1 เดือน -3 ปี เป็นต้น
-
จะใช้ sql ยังไงครับ ถึงจะกำหนด เงื่อนไขระดับ 1 ปี 1 เดือน -3 ปี เป็นต้น
ลองศึกษาและประยุกต์ใช้ report ที่ผมทำจาก http://hosxp.net/index.php?option=com_smf&Itemid=28&topic=17347.msg140875
-
อาจจะบ้านๆ หน่อยน่ะครับ นับเดือน ไล่ไปเลย ;D ;D ;D
select pt.*,ov.*
from vn_stat ov
inner join patient pt on pt.hn = ov.hn
inner join ovst on ovst.vn = ov.vn
where ov.vstdate between '2010-09-01' and '2010-09-10' and ov.spclty = '01'
แล้วก็เปลี่ยนช่วงปีเอง
and timestampdiff(MONTH,pt.birthday,ov.vstdate) between 0 and 12
หรือ
and timestampdiff(MONTH,pt.birthday,ov.vstdate) between 13 and 36
หรือ
and timestampdiff(MONTH,pt.birthday,ov.vstdate) between 37 and 71
หรือ
and timestampdiff(MONTH,pt.birthday,ov.vstdate) between 72 and 155
หรือ
and timestampdiff(MONTH,pt.birthday,ov.vstdate) between 156 and 216
หรือจะนับจำนวนรวม ตามช่วงอายุที่กำหนดเมื่อกี้ก็ ;) ;)
select 'ผู้มารับบริการ แยกตามช่วงอายุ' as nn
,sum(case when timestampdiff(MONTH,pt.birthday,ov.vstdate) between 0 and 12 then 1 else 0 end) as 0_1
,sum(case when timestampdiff(MONTH,pt.birthday,ov.vstdate) between 13 and 36 then 1 else 0 end) as 11_3
,sum(case when timestampdiff(MONTH,pt.birthday,ov.vstdate) between 37 and 71 then 1 else 0 end) as 31_511
,sum(case when timestampdiff(MONTH,pt.birthday,ov.vstdate) between 72 and 155 then 1 else 0 end) as 6_1211
,sum(case when timestampdiff(MONTH,pt.birthday,ov.vstdate) between 156 and 216 then 1 else 0 end) as 13_18
from vn_stat ov
inner join patient pt on pt.hn = ov.hn
inner join ovst on ovst.vn = ov.vn
where ov.vstdate between '2010-09-01' and '2010-09-10' and ov.spclty = '01'
-
;D ;D ;D