ソースコード
select 
 x.PF_CODE as 都道府県コード,
 x.PF_NAME as 都道府県名,
 max(case when ranking = 1 then x.ddd else null end) as '1位 国名',
 sum(case when ranking = 1 then x.amt else 0 end)  as '1位 人数',
 max(case when ranking = 2 then x.ddd else null end)  as '2位 国名',
 sum(case when ranking = 2 then x.amt else 0 end)  as '2位 人数',
 max(case when ranking = 3 then x.ddd else null end) as '3位 国名',
 sum(case when ranking = 3 then x.amt else 0 end)  as '3位 人数',
 sum(amt) as 合計人数
from 
( 
select 
 f.PF_CODE,
 f.NATION_CODE,
 f.AMT,
 n.NATION_NAME as ddd,
 p.PF_NAME, 
 rank() over(partition by f.pf_code order by  f.amt desc) as ranking
from 
 FOREIGNER as f
inner join
 NATIONALITY as n on f.NATION_CODE = n.NATION_CODE and n.NATION_CODE <> '113'
inner join
 PREFECTURE as p on f.PF_CODE = p.PF_CODE
) as x

group by 
 x.pf_name, x.pf_code
order by
 合計人数 desc,
 都道府県コード asc
;
提出情報
提出日時2022/07/20 20:50:57
コンテスト第1回 SQLコンテスト
問題外国籍分布
受験者omg_granddd
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量103 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
WA
103 MB
データパターン2
AC
101 MB