ソースコード
select
t1.PF_CODE as 都道府県コード,
PF_NAME as 都道府県名,
case when rank_amt_by_pref = 1 then NATION_NAME else 0 end as "1位 国名", 
sum(case when rank_amt_by_pref = 1 then sum_amt else 0 end) as "1位 人数",
replace(
  group_concat(case when rank_amt_by_pref = 2 then NATION_NAME else "" end, ";")
, ";", "") as "2位 国名",
sum(case when rank_amt_by_pref = 2 then sum_amt else 0 end) as "2位 人数",
replace(
  group_concat(case when rank_amt_by_pref = 4 then NATION_NAME else "" end, ";")
, ";", "") as "3位 国名",
sum(case when rank_amt_by_pref = 3 then sum_amt else 0 end) as "3位 人数",
sum(sum_amt) as "合計人数"
from (
    select
    RANK () OVER(
        partition by PF_CODE
        order by sum_amt desc
    ) rank_amt_by_pref,
    PF_CODE,
    NATION_CODE,
    sum_amt
    from (
        select
        PF_CODE,
        NATION_CODE,
        sum(AMT) as sum_amt
        from FOREIGNER
        where NATION_CODE <> '113'
        group by PF_CODE, NATION_CODE
    ) as t0
) as t1
inner join NATIONALITY on NATIONALITY.NATION_CODE = t1.NATION_CODE
inner join PREFECTURE on PREFECTURE.PF_CODE = t1.PF_CODE
group by t1.PF_CODE
order by 合計人数 desc, 都道府県コード asc
;
提出情報
提出日時2022/07/20 20:48:36
コンテスト第1回 SQLコンテスト
問題外国籍分布
受験者tenten-tonton-tantan
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量98 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
97 MB
データパターン2
WA
98 MB