SQL ที่เขียน
select p.cid,right(concat('00000',p.person_id),6) pid,concat(p.fname,' ',p.lname) fname,p.birthdate,p.nationality,p.person_discharge_id,t.pp_special_code,o.vstdate
,timestampdiff(year,p.birthdate,o.vstdate) age_y,o.vn,o.pttype,c.name c_name,o.pttypeno
,if(timestampdiff(year,p.birthdate,o.vstdate) between 50 and 70 and p.nationality=99 and p.person_discharge_id=9,'นับผลงาน','ไม่ตรงเงื่อนไข') mean
,q.seq_id
from pp_special pp
inner join ovst o on pp.vn=o.vn
left join ovst_seq q on o.vn=q.vn
inner join pttype c on o.pttype=c.pttype
inner join person p on o.hn=p.patient_hn
inner join pp_special_type t on pp.pp_special_type_id=t.pp_special_type_id
where t.pp_special_code in('1B0060','1B0061') and left(pp.entry_datetime,10) between '2018-10-01' and '2019-09-30'
อธิบายส่วนของรายงาน
right(concat('00000',p.person_id),6) เป็นคำสั่งรวมข้อความ 2 ชุด คือ 00000 และ person_id ของตาราง person เช่น person_id=555 เมื่อใช้คำสั่ง concat('00000',p.person_id) จะได้เป็น 00000555 แต่เมื่อใช้คำสั่ง right(,6) ครอบคำสั่ง concat จะเป็นการให้แสดงข้อมูลโดยนับจากทางขวามา 6 ตำแหน่ง ค่าที่แสดงออกมาจะเป็น 000555 แทน
timestampdiff(year,p.birthdate,o.vstdate) จะเป็นคำสั่งหาผลต่างระหว่างวันที่ 2 วันที่โดยกำหนดให้ออกมาเป็นปี (year) โดยใช้วันเกิด(birthdate) ของตาราง person และ วันรับบริการ(vstdate) ของตาราง ovst
ดาวน์โหลดรายงานคลิกที่นี่
No comments:
Post a Comment