ソースコード
select
fore.pf_code as "都道府県コード",
pref.pf_name as "都道府県名",
max(case when rank() over (partition by fore.pf_code, fore.nation_code order by fore.amt, fore.nation_code) = 1 then nat.nation_name else null end) as "1位 国名",
sum(case when rank() over (partition by fore.pf_code, fore.nation_code order by fore.amt, fore.nation_code) = 1 then fore.amt else null end) as "1位 人数",
max(case when rank() over (partition by fore.pf_code, fore.nation_code order by fore.amt, fore.nation_code) = 2 then nat.nation_name else null end) as "2位 国名",
sum(case when rank() over (partition by fore.pf_code, fore.nation_code order by fore.amt, fore.nation_code) = 2 then fore.amt else null end) as "2位 人数",
max(case when rank() over (partition by fore.pf_code, fore.nation_code order by fore.amt, fore.nation_code) = 3 then nat.nation_name else null end) as "3位 国名",
sum(case when rank() over (partition by fore.pf_code, fore.nation_code order by fore.amt, fore.nation_code) = 3 then fore.amt else null end) as "3位 人数",
sum(amt) as "合計人数"
from
foreigner fore
inner join prefecture pref
on fore.pf_code = pref.pf_code
inner join nationality nat
on fore.nation_code = nat.nation_code 
group by
fore.pf_code
order by
"合計人数" desc,
"都道府県コード"
提出情報
提出日時2022/07/20 21:59:54
コンテスト第1回 SQLコンテスト
問題外国籍分布
受験者Reliability
状態 (詳細)RE
(Runtime Error: 実行時エラー)
メモリ使用量103 MB
メッセージ
SQLITE_ERROR: misuse of window function rank()
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
RE
103 MB
データパターン2
RE
49 MB