ソースコード
WITH CD110 AS(
SELECT
    PF_CODE AS CODE
    , CATEGORY_CODE
    , sum(AMT) AS AMT
FROM DRINK_HABITS
WHERE GENDER_CODE IN ('2', '3')
    AND CATEGORY_CODE IN ('110')
GROUP BY CATEGORY_CODE, PF_CODE
)
, CD120 AS(
SELECT
    PF_CODE AS CODE
    , CATEGORY_CODE
    , sum(AMT) AS AMT
    -- , 都道府県毎の毎日飲酒率 AS PERCENTAGE
FROM DRINK_HABITS
WHERE GENDER_CODE IN ('2', '3')
    AND CATEGORY_CODE IN ('120')
GROUP BY CATEGORY_CODE, PF_CODE
)

SELECT 
    CD110.CODE AS CODE
    , P.PF_NAME AS NAME
    , ROUND(CAST(CD120.AMT AS DOUBLE) / 
    CAST(CD110.AMT AS DOUBLE) * 100, 1) AS PERCENTAGE
FROM CD110 JOIN CD120
    ON CD110.CODE = CD120.CODE
    LEFT OUTER JOIN PREFECTURE AS P
        ON CD110.CODE = P.PF_CODE
ORDER BY PERCENTAGE DESC, CODE DESC
提出情報
提出日時2024/07/30 11:19:48
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者sql_yowayowa
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB