コンテストの制限時間が終了しました。
以降も提出を行うことができますが、順位集計には反映されません。
以降も提出を行うことができますが、順位集計には反映されません。
ソースコード
SELECT DISTINCT
F.PF_CODE AS 都道府県コード
,RANKING.PF_NAME AS 都道府県名
,FIRST_VALUE(RANKING.NATION_NAME) OVER (PARTITION BY RANKING.PF_CODE ORDER BY RANKING.JUNI ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS [1位 国名]
,FIRST_VALUE(RANKING.AMT) OVER (PARTITION BY RANKING.PF_CODE ORDER BY RANKING.JUNI ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS [1位 人数]
,NTH_VALUE(RANKING.NATION_NAME,2) OVER (PARTITION BY RANKING.PF_CODE ORDER BY RANKING.JUNI ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS [2位 国名]
,NTH_VALUE(RANKING.AMT,2) OVER (PARTITION BY RANKING.PF_CODE ORDER BY RANKING.JUNI ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS [2位 人数]
,NTH_VALUE(RANKING.NATION_NAME,3) OVER (PARTITION BY RANKING.PF_CODE ORDER BY RANKING.JUNI ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS [3位 国名]
,NTH_VALUE(RANKING.AMT,3) OVER (PARTITION BY RANKING.PF_CODE ORDER BY RANKING.JUNI ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS [3位 人数]
,SUM(RANKING.AMT) OVER (PARTITION BY F.PF_CODE) AS [合計人数]
FROM FOREIGNER AS F
INNER JOIN
(
SELECT
F.PF_CODE
,F.NATION_CODE
,P.PF_NAME
,N.NATION_NAME
,RANK() OVER ( PARTITION BY F.PF_CODE ORDER BY SUM( AMT ) DESC ) AS JUNI
,SUM(AMT) AS AMT
FROM FOREIGNER AS F
INNER JOIN PREFECTURE AS P
ON F.PF_CODE = P.PF_CODE
INNER JOIN NATIONALITY AS N
ON F.NATION_CODE = N.NATION_CODE
WHERE F.NATION_CODE <> '113'
GROUP BY F.PF_CODE
,F.NATION_CODE
,P.PF_NAME
,N.NATION_NAME
) AS RANKING
ON F.PF_CODE = RANKING.PF_CODE
AND F.NATION_CODE = RANKING.NATION_CODE
GROUP BY F.PF_CODE,RANKING.PF_NAME,RANKING.NATION_NAME
ORDER BY [合計人数] DESC, [都道府県コード] ASC
提出情報
提出日時 | 2022/07/20 21:26:03 |
コンテスト | 第1回 SQLコンテスト |
問題 | 外国籍分布 |
受験者 | sitakkun |
状態 (詳細) | WA (Wrong Answer: 誤答) |
メモリ使用量 | 102 MB |
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
WA
41 MB
データパターン2
AC
102 MB