ソースコード
WITH counts AS (
    SELECT
        DRINK_HABITS.PF_CODE
        , PREFECTURE.PF_NAME
        , CATEGORY_CODE
        , SUM(AMT) AS counts
    FROM
        DRINK_HABITS
        INNER JOIN
        PREFECTURE
        ON
        DRINK_HABITS.PF_CODE = PREFECTURE.PF_CODE
    WHERE
        GENDER_CODE IN ('2', '3')
    GROUP BY
        1, 2, 3
)
, ratio AS (
SELECT
    PF_CODE
    , PF_NAME
    , MAX(CASE WHEN CATEGORY_CODE = '110' THEN counts ELSE NULL END) AS counts_110
    , MAX(CASE WHEN CATEGORY_CODE = '120' THEN counts ELSE NULL END) AS counts_120
FROM
    counts
GROUP BY
    1, 2
)
SELECT
    PF_CODE AS CODE
    , PF_NAME AS NAME
    , ROUND((CAST(counts_120 AS FLOAT) / counts_110)*100.0, 1) AS PERCENTAGE
FROM
    ratio
ORDER BY
    PERCENTAGE DESC
    , PF_CODE DESC
;
提出情報
提出日時2024/05/03 17:15:27
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者mameg
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
85 MB