select r.*,concat(p.pname,p.fname," ",p.lname) as ptname ,i.*, w.name as ward_name,d.name,i.prediag,p.drugallergy,s.name,sp.name,a.an,op.bw,op.bps,op.cc,p.clinic,
a.age_y,a.age_m,a.age_d,i2.bedno,
y.name as pttype_name ,date_add(r.start_date,interval 1 day ) as 'day2 ',
interval 2 day + r.start_date as day3 ,
interval 3 day + r.start_date as day4 ,
interval 4 day + r.start_date as day5 ,
interval 5 day + r.start_date as day6 ,
interval 6 day + r.start_date as day7 ,
interval 7 day + r.start_date as day8 ,
interval 8 day + r.start_date as day9 ,
interval 9 day + r.start_date as day10 ,
interval 10 day + r.start_date as day11 ,
interval 11 day + r.start_date as day12 ,
interval 12 day + r.start_date as day13 ,
interval 13 day + r.start_date as day14
from ipd_profile_print r
left outer join ipt i on i.an = r.an
left outer join an_stat a on a.an = r.an
left outer join spclty sp on sp.spclty =a.spclty
left outer join doctor d on d.code = r.doctor
left outer join patient p on p.hn = i.hn
left outer join sex s on s.code = p.sex
left outer join ward w on w.ward = i.ward
left outer join pttype y on y.pttype = i.pttype
left outer join iptadm i2 on i2.an = i.an
left outer join opdscreen op on op.hn = i.hn
where r.an = "520101277"
group by r.name
order by r.med_plan_number
เติมฟิว start_date มีตารางเดียว พออัพเวอร์ชัน มี 2 ตารางขึ้นไป ให้เพิ่ม r.start_date เป็นต้น