รายงานเก่าที่อ.ท่านใดทำไว้นานแล้วครับ ผมก็จำไม่ได้ ขออภัยมา ณ โอกาสนี้ครับ
อย่าลืมแก้ไข lab_items_code นะครับ
set @d1 = '2013-10-01';
set @d2 = '2014-03-31';
select *
from
(select v.hn,concat(p.pname,p.fname,space(3),p.lname) as ptname, v.aid,
(select lo.lab_order_result from lab_order lo
left outer join lab_head lh on lh.lab_order_number=lo.lab_order_number
where lo.lab_items_code=66 and lh.hn=v.hn
and lh.order_date between @d1 and @d2
order by lh.report_date desc,lh.report_time desc limit 0,1) as fbs
,
(select lo2.lab_order_result from lab_order lo2
left outer join lab_head lh2 on lh2.lab_order_number=lo2.lab_order_number
where lo2.lab_items_code=66 and lh2.hn=v.hn
order by lh2.report_date desc,lh2.report_time desc limit 1,1) as fbs1
,
(select lo3.lab_order_result from lab_order lo3
left outer join lab_head lh3 on lh3.lab_order_number=lo3.lab_order_number
where lo3.lab_items_code=66 and lh3.hn=v.hn
order by lh3.report_date desc,lh3.report_time desc limit 2,1) as fbs2
from vn_stat v
left join patient p on p.hn = v.hn
where v.vstdate between @d1 and @d2
and v.hn in (select hn from clinicmember where clinic="001")
group by v.hn
order by v.aid desc ,p.pname,p.fname,p.lname
) as ttemp
where fbs between 70 and 130 and fbs1 between 70 and 130 and fbs2 between 70 and 130