ลองปรับดูตามข้างล่างครับ
ChangeReportSQL(' 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=275 and lh.hn=v.hn '
+ ' and lh.order_date between "'+ds1+'" and "'+ds2+'" '
+ ' 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=275 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=275 and lh3.hn=v.hn '
+ ' order by lh3.report_date desc,lh3.report_time desc limit 2,1) as fbs2, '
+' (select lo4.lab_order_result from lab_order lo4 '
+' left outer join lab_head lh4 on lh4.lab_order_number=lo4.lab_order_number '
+' where lo4.lab_items_code=123 and lh4.hn=v.hn '
+' order by lh4.report_date desc,lh4.report_time desc limit 0,1) as HBA1C '{อันนี้อันใหม่ครับ}
{+ ' lo.lab_order_result as HBA1C ' อันนี้ตัวเดิมนะครับ}
+ ' from vn_stat v '
+ ' left join patient p on p.hn = v.hn '
+ ' left join lab_head lh on p.hn=lh.hn '
+ ' left join lab_order lo on lh.lab_order_number=lo.lab_order_number '
+ ' where v.vstdate between "'+ds1+'" and "'+ds2+'" '
+ ' and lo.lab_items_code ="306" '
+ ' and v.hn in (select hn from clinicmember where clinic="001" and clinic_member_status_id="1" ) '
+ ' group by v.hn '
+ ' order by v.aid desc ,p.pname,p.fname,p.lname) as ttemp '
+ ' where HBA1C <=6.5 ')