พยาบาลเค้าอยากได้ข้อมูลคนไข้ที่เป็นโรคเบาหวานที่มีผลน้ำตาลในแต่ละเดือนต่างกันเท่าไร ผมต้องทำไงดีครับ
ผมทำได้แบบนี้อ่ะครับ
select vn.hn,concat(pt.pname,pt.fname,' ',pt.lname)as name,vn.vstdate,vn.age_y,vn.pdx,vn.dx0,vn.dx1,vn.dx2,vn.dx3,vn.dx4,vn.dx5,lo.lab_items_code
,lo.lab_order_result from vn_stat vn
left outer join patient pt on vn.hn = pt.hn
left outer join lab_head lh on vn.vn =lh.vn
left outer join lab_order lo on lh.lab_order_number = lo.lab_order_number
where vn.vstdate between '2010-10-01' and '2010-10-31'
and (vn.pdx in ('E10','E101','E102','E103','E104','E105','E106','E107','E108','E109'
,'E11','E110','E111','E112','E113','E114','E115','E116','E117','E118','E119','E162','R739')
or vn.dx0 in('E10','E101','E102','E103','E104','E105','E106','E107','E108','E109'
,'E11','E110','E111','E112','E113','E114','E115','E116','E117','E118','E119','E162','R739')
or vn.dx1 in('E10','E101','E102','E103','E104','E105','E106','E107','E108','E109'
,'E11','E110','E111','E112','E113','E114','E115','E116','E117','E118','E119','E162','R739')
or vn.dx2 in('E10','E101','E102','E103','E104','E105','E106','E107','E108','E109'
,'E11','E110','E111','E112','E113','E114','E115','E116','E117','E118','E119','E162','R739')
or vn.dx3 in('E10','E101','E102','E103','E104','E105','E106','E107','E108','E109'
,'E11','E110','E111','E112','E113','E114','E115','E116','E117','E118','E119','E162','R739')
or vn.dx4 in('E10','E101','E102','E103','E104','E105','E106','E107','E108','E109'
,'E11','E110','E111','E112','E113','E114','E115','E116','E117','E118','E119','E162','R739')
or vn.dx5 in('E10','E101','E102','E103','E104','E105','E106','E107','E108','E109'
,'E11','E110','E111','E112','E113','E114','E115','E116','E117','E118','E119','E162','R739') )
and lo.lab_items_code in ('88','89')
จะเอาผลมาลบกันยังไง งง ครับ