select
個人名,
max(case カラム番号 when 1 then エラー end) as エラー1回目,
max(case カラム番号 when 2 then エラー end) as エラー2回目,
max(case カラム番号 when 3 then エラー end) as エラー3回目,
max(case カラム番号 when 4 then エラー end) as エラー4回目,
max(case カラム番号 when 5 then エラー end) as エラー5回目
from (
select
個人名,
case
when not エラーA is null then 'エラーA'
when not エラーB is null then 'エラーB'
when not エラーC is null then 'エラーC'
end as エラー
row_number() over (
partition by 個人名
order by 日付 asc, オーダ番号 asc) as カラム番号
from エラー履歴
)
group by 個人名