ソースコード
select
A.PF_CODE AS CODE,
B.PF_NAME AS NAME,
ROUND(CAST(SUM(A.AMT) AS REAL)/CAST(C.CA AS REAL)*100,1)AS PERCENTAGE

FROM DRINK_HABITS AS A
LEFT JOIN PREFECTURE AS B
ON A.PF_CODE = B.PF_CODE
LEFT JOIN (select
PF_CODE,
SUM(AMT) AS CA
FROM DRINK_HABITS 
WHERE 1=1 
AND (GENDER_CODE = '2' OR GENDER_CODE = '3')
AND CATEGORY_CODE = '110'
GROUP BY PF_CODE
) AS C
ON A.PF_CODE = C.PF_CODE

WHERE 1=1 
AND (GENDER_CODE = '2' OR GENDER_CODE = '3')
AND CATEGORY_CODE = '120'
GROUP BY B.PF_CODE
ORDER BY PERCENTAGE DESC,CODE DESC
;


       
提出情報
提出日時2022/09/21 19:13:16
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者anpan
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量105 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
105 MB
データパターン2
AC
105 MB