你能试试这个吗(我假设Patient\u Id是指患者Id的确切列名):
select vst_int_id,
max(case when seq = 1 then d.chg_dtl_int_id end) chg1,
max(case when seq = 2 then d.chg_dtl_int_id end) chg2,
max(case when seq = 3 then d.chg_dtl_int_id end) chg3,
max(case when seq = 4 then d.chg_dtl_int_id end) chg4,
max(case when seq = 5 then d.chg_dtl_int_id end) chg5,
p.Patient_ID
from (
select c.vst_int_id, c.chg_dtl_int_id,
row_number() over(partition by c.vst_int_id order by chg_dtl_int_id) seq
from CHARGE_DETAIL c
where c.vst_int_id = '14568778'
) d
inner join PAT_VISIT p ON p.vst_int_id = d.vst_int_id
group by d.vst_int_id, p.Patient_ID