ソースコード
SELECT
	DISTINCT T1.PF_CODE AS CODE
	,T2.PF_NAME AS NAME
--	,T3.DRINK AS DRINK
--	,T4.TOTAL AS TOTAL
	,ROUND(DRINK * 1.0 * 100 / TOTAL,1) AS PERCENTAGE
FROM DRINK_HABITS T1
INNER JOIN PREFECTURE T2
ON	T1.PF_CODE = T2.PF_CODE
--WHERE
--	T1.GENDER_CODE IN ('2','3')
--GROUP BY T1.PF_CODE

INNER JOIN (
	SELECT
		T1.PF_CODE AS CODE
		,T2.PF_NAME AS NAME
		,SUM(T1.AMT) AS DRINK
	FROM DRINK_HABITS T1
	INNER JOIN PREFECTURE T2
	ON	T1.PF_CODE = T2.PF_CODE
	WHERE
		T1.GENDER_CODE IN ('2','3')
	AND	T1.CATEGORY_CODE = '120'
	GROUP BY T1.PF_CODE
) T3
ON	T1.PF_CODE = T3.CODE

INNER JOIN (
	SELECT
		T1.PF_CODE AS CODE
		,T2.PF_NAME AS NAME
		,SUM(T1.AMT) AS TOTAL
	FROM DRINK_HABITS T1
	INNER JOIN PREFECTURE T2
	ON	T1.PF_CODE = T2.PF_CODE
	WHERE
		T1.GENDER_CODE IN ('2','3')
	AND	T1.CATEGORY_CODE = '110'
	GROUP BY T1.PF_CODE
) T4
ON	T1.PF_CODE = T4.CODE

ORDER BY
	PERCENTAGE DESC
	,CODE DESC



提出情報
提出日時2023/06/24 18:37:17
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者silentkid
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
77 MB