ソースコード
SELECT
	DISTINCT(T1.AREA_CODE) AS CODE
	,T1.AREA_NAME AS NAME
	,T3."2022_RANK" AS "2022_RANK"
	,T3."2022_RATIO" AS "2022_RATIO"
	,T4."2017_RANK" AS "2017_RANK"
	,T4."2017_RATIO" AS "2017_RATIO"
	,T5."2012_RANK" AS "2012_RANK"
	,T5."2012_RATIO" AS "2012_RATIO"
FROM AREA T1
INNER JOIN HOUSEHOLD_SURVEY T2
ON T1.AREA_CODE = T2.AREA_CODE

INNER JOIN(
	SELECT
		T1.AREA_CODE AS CODE
		,T1.AREA_NAME AS NAME
		,DENSE_RANK() OVER(ORDER BY ROUND(CAST(T2.FOOD_EXP AS REAL) * 100 / CAST(T2.CONSUMPTION_EXP AS REAL),1) ASC) AS "2022_RANK"
		,ROUND(CAST(T2.FOOD_EXP AS REAL) * 100 / CAST(T2.CONSUMPTION_EXP AS REAL),1) || '%' AS "2022_RATIO"
	FROM AREA T1
	INNER JOIN HOUSEHOLD_SURVEY T2
	ON T1.AREA_CODE = T2.AREA_CODE
	WHERE T2.SURVEY_YEAR = 2022
	ORDER BY 
		"2022_RANK" ASC
		,CODE DESC
	) T3
ON T1.AREA_CODE = T3.CODE

INNER JOIN(
	SELECT
		T1.AREA_CODE AS CODE
		,T1.AREA_NAME AS NAME
		,DENSE_RANK() OVER(ORDER BY ROUND(CAST(T2.FOOD_EXP AS REAL) * 100 / CAST(T2.CONSUMPTION_EXP AS REAL),1) ASC) AS "2017_RANK"
		,ROUND(CAST(T2.FOOD_EXP AS REAL) * 100 / CAST(T2.CONSUMPTION_EXP AS REAL),1) || '%' AS "2017_RATIO"
	FROM AREA T1
	INNER JOIN HOUSEHOLD_SURVEY T2
	ON T1.AREA_CODE = T2.AREA_CODE
	WHERE T2.SURVEY_YEAR = 2017
	ORDER BY 
		"2017_RANK" ASC
		,CODE DESC
	) T4
ON T1.AREA_CODE = T4.CODE

INNER JOIN(
	SELECT
		T1.AREA_CODE AS CODE
		,T1.AREA_NAME AS NAME
		,DENSE_RANK() OVER(ORDER BY ROUND(CAST(T2.FOOD_EXP AS REAL) * 100 / CAST(T2.CONSUMPTION_EXP AS REAL),1) ASC) AS "2012_RANK"
		,ROUND(CAST(T2.FOOD_EXP AS REAL) * 100 / CAST(T2.CONSUMPTION_EXP AS REAL),1) || '%' AS "2012_RATIO"
	FROM AREA T1
	INNER JOIN HOUSEHOLD_SURVEY T2
	ON T1.AREA_CODE = T2.AREA_CODE
	WHERE T2.SURVEY_YEAR = 2012
	ORDER BY 
		"2012_RANK" ASC
		,CODE DESC
	) T5
ON T1.AREA_CODE = T5.CODE

ORDER BY 
	"2022_RANK" ASC
	,CODE DESC

提出情報
提出日時2023/12/17 19:29:54
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者silentkid
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
85 MB
データパターン3
AC
86 MB