ソースコード
WITH TOTAL_DRINK AS
(
    SELECT
        PF_CODE
        ,SUM(AMT) AS TOTAL_NUM
    FROM
        DRINK_HABITS
    WHERE
        GENDER_CODE IN ('2', '3')
        AND
        CATEGORY_CODE = '110'
    GROUP BY
        PF_CODE
)
, EVERYDAY_DRINK AS
(
    SELECT
        PF_CODE
        ,SUM(AMT) AS EVERYDAY_TOTAL
    FROM
        DRINK_HABITS
    WHERE
        GENDER_CODE IN ('2', '3')
        AND
        CATEGORY_CODE = '120'
    GROUP BY
        PF_CODE
)
SELECT
    T.PF_CODE AS CODE
    ,P.PF_NAME AS NAME
    ,ROUND(CAST(EVERYDAY_TOTAL AS REAL) / TOTAL_NUM * 100, 1) AS PERCENTAGE
FROM
    TOTAL_DRINK AS T
INNER JOIN
    EVERYDAY_DRINK AS E
ON T.PF_CODE = E.PF_CODE
INNER JOIN
    PREFECTURE AS P
ON T.PF_CODE = P.PF_CODE
ORDER BY    
    PERCENTAGE DESC, CODE DESC
提出情報
提出日時2023/10/31 13:07:21
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者Macchapi
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量76 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
76 MB
データパターン2
AC
75 MB