ช่วย ๆ กันครับ ผมก็นำลังไล่ดึงอยู่ครับ นำไปประยุกต์ดูครับ
select v.hn,v.vn,v.vstdate,concat(p.pname,' ',p.fname,' ',p.lname) as fullname,lo.lab_items_name_ref,lo.lab_order_result,v.pdx,
if (lo.lab_items_name_ref='Glucose',lo.lab_order_result,' ') as Gllab,
if (lo.lab_items_name_ref='Bun',lo.lab_order_result,' ') as Bunlab,
if (lo.lab_items_name_ref='Chol Total',lo.lab_order_result,' ') as Cholab,
if (lo.lab_items_name_ref='Chol HDL',lo.lab_order_result,' ') as Chol_HDL,
if (lo.lab_items_name_ref='Triglyceride',lo.lab_order_result,' ') as Triglyceride_HDL,
if (lo.lab_items_name_ref='Uric acid',lo.lab_order_result,' ') as Uric_acid,
if (lo.lab_items_name_ref='Hb A1c',lo.lab_order_result,' ') as Hb_A1c,
if (lo.lab_items_name_ref='Microalbumin',lo.lab_order_result,' ') as Microalbumin,
if (lo.lab_items_name_ref='Electrolyte',lo.lab_order_result,' ') as Electrolyte,
if (lo.lab_items_name_ref='Na',lo.lab_order_result,' ') as Na,
if (lo.lab_items_name_ref='K',lo.lab_order_result,' ') as K,
if (lo.lab_items_name_ref='CI',lo.lab_order_result,' ') as CI,
if (lo.lab_items_name_ref='tCO2',lo.lab_order_result,' ') as tCO2,
if (lo.lab_items_name_ref='Protein Strip',lo.lab_order_result,' ') as Protein_Strip,
if (lo.lab_items_name_ref='Mialbumin strip',lo.lab_order_result,' ') as Mialbumin_Strip,
os.cc
,bp.bps,bp.bpd,os.height,bmi
from vn_stat v
left outer join opdscreen os on os.vn=v.vn
left outer join opdscreen_bp bp on bp.vn=v.vn
left outer join patient p on v.hn=p.hn
left outer join lab_head lh on lh.vn=v.vn
left outer join lab_order lo on lo.lab_order_number=lh.lab_order_number
left outer join lab_items li on li.lab_items_code=lo.lab_items_code
where ((v.pdx like 'E10%') or (v.pdx like 'E11%') or (v.pdx like 'E12%') or (v.pdx like 'E13%')
or (v.pdx like 'E14%')) and (v.vstdate between '2011-04-01' and '2011-04-30')
and (lo.lab_items_name_ref in ('Glucose','Bun','Chol Total','Chol HDL','Triglyceride','Uric acid','Hb A1c''Microalbumin','Electrolyte','Na',
'K','CI','tCO2','Protein Strip','Mialbumin strip')) and lo.confirm='Y' and lo.lab_order_result<>'Negative'
group by v.vn
order by v.vn,v.vstdate,lo.lab_items_name_ref