ソースコード
with DRINK_HABITS_total as(
    select
        PF_CODE
        ,CATEGORY_CODE
        ,sum(AMT) as total

    from
        DRINK_HABITS
        
    where
        GENDER_CODE in (2,3)
        and CATEGORY_CODE in (110)

    group by
        PF_CODE
        ,CATEGORY_CODE
)

,DRINK_HABITS_drink as(
    select
        PF_CODE
        ,CATEGORY_CODE
        ,sum(AMT) as drink_sum

    from
        DRINK_HABITS
        
    where
        GENDER_CODE in (2,3)
        and CATEGORY_CODE in (120)

    group by
        PF_CODE
        ,CATEGORY_CODE
)


select
    A.PF_CODE as CODE
    ,PR.PF_NAME as NAME
    ,round(cast(B.drink_sum as real)/cast(A.total as real) *100,1) as PERCENTAGE

from
    DRINK_HABITS_total as A

inner join
    DRINK_HABITS_drink as B
    on A.PF_CODE = B.PF_CODE

    ,PREFECTURE as PR
    on A.PF_CODE = PR.PF_CODE

order by
    PERCENTAGE desc
    ,CODE desc

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