ソースコード

with rank as
  (
   SELECT
     PF_CODE
     , NATION_CODE
     , AMT
     , row_number() OVER(partition by pf_code order by amt DESC,nation_code ASC) AS rank
   from
     foreigner
   where
     nation_code <> 113 --その他除く
  )
, rank2 as
(
select
  pf_code
  , STRING_AGG(case when rank = 1 then nation_code else null END) AS no1_nation_code
  , SUM(case when rank = 1 then amt         else 0 END) AS no1_nation_amt
  , STRING_AGG(case when rank = 2 then nation_code else null END) AS no2_nation_code
  , SUM(case when rank = 2 then amt         else 0 END) AS no2_nation_amt
  , STRING_AGG(case when rank = 3 then nation_code else null END) AS no3_nation_code
  , SUM(case when rank = 3 then amt         else 0 END) AS no3_nation_amt
from
  rank
GROUP BY
  1
)

select
  pf_code
  , pf_name
  , no1_nation_name
  , no1_nation_amt
  , no2_nation_name
  , no2_nation_amt
  , no3_nation_name
  , no3_nation_amt
from
  rank2
INNER JOIN
  nationality
ON
  nationality.nation_code = rank2.no1_nation_code
INNER JOIN
  nationality
ON
  nationality.nation_code = rank2.no2_nation_code
INNER JOIN
  nationality
ON
  nationality.nation_code = rank2.no3_nation_code
inner join
  prefecture
on rank2.pf_code = prefecture.pf_code
提出情報
提出日時2022/07/20 21:14:40
コンテスト第1回 SQLコンテスト
問題外国籍分布
受験者rebirds
状態 (詳細)RE
(Runtime Error: 実行時エラー)
メモリ使用量103 MB
メッセージ
SQLITE_ERROR: no such function: STRING_AGG
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
RE
102 MB
データパターン2
RE
103 MB