ของผมแบบนี้เด้อครับ
select r1.name as HN,r1.name1 as Pt_Name,r1.name2 as Pt_Age,r1.name4 as Sex,r1.date1 as BirthDay,
concat("เลขที่ ",r5.name5," หมู่ ",r5.name6," ถ. ",r5.name7," ต. ",r5.name8," อ. ",r5.name9," จ. ",r5.name10) as fulladdress,
r2.name as Occupation,r2.name1 as MarryStatus,r2.name2 as Nationality,r2.name3 as Citizenship,r2.name4 as Religion,
r3.name as BloodGroup,r3.name1 as DrugAllergy,r3.name2 as HomeTel,r3.name3 as InformName,r3.name4 as InformAddr,
r4.name as InformRelation,r4.name1 as Father,r4.name2 as Mother,r4.name3 as SPSName,r4.name4 as CardName,
r5.name as CardCODE,r5.name1 as PtRight,r5.name2 as PtRightCode,r5.date1 as RightExpire
from tempreport r1
left outer join tempreport r2 on r2.reportname=r1.reportname and r2.id=r1.id and r2.num=2
left outer join tempreport r3 on r3.reportname=r1.reportname and r3.id=r1.id and r3.num=3
left outer join tempreport r4 on r4.reportname=r1.reportname and r4.id=r1.id and r4.num=4
left outer join tempreport r5 on r5.reportname=r1.reportname and r5.id=r1.id and r5.num=5
where
r1.id="ID-{B276ABDB-56E9-4795-AE2C-EB0D3FFC126C}" and
r2.id="ID-{B276ABDB-56E9-4795-AE2C-EB0D3FFC126C}" and
r3.id="ID-{B276ABDB-56E9-4795-AE2C-EB0D3FFC126C}" and
r4.id="ID-{B276ABDB-56E9-4795-AE2C-EB0D3FFC126C}" and
r5.id="ID-{B276ABDB-56E9-4795-AE2C-EB0D3FFC126C}" and
r1.reportname="RB1T02" and r1.num=1