ソースコード
select
      PF_CODE as CODE
    , PF_NAME as NAME
    , ROUND( ( (DRINK*1.0) / (TOTAL*1.0) )*100, 1) as PERCENTAGE
from
    (
    select
        PF_CODE
        , PF_NAME
        , sum(case when CATEGORY_CODE = '110' then AMT else 0 end) as TOTAL
        , sum(case when CATEGORY_CODE = '120' then AMT else 0 end) as DRINK
    from
        (
        select
            CATEGORY_CODE
            , PF_CODE
            , PF_NAME
            , sum(AMT) as AMT
        from
            (
            select
                DRINK_HABITS.CATEGORY_CODE
                , DRINK_HABITS.GENDER_CODE
                , DRINK_HABITS.PF_CODE
                , PREFECTURE.PF_NAME
                , DRINK_HABITS.AMT
            from DRINK_HABITS
                left outer join PREFECTURE using(PF_CODE)
            )
        where
            GENDER_CODE in (2,3)
        group by CATEGORY_CODE, PF_CODE, PF_NAME
        )
    group by PF_CODE, PF_NAME
    )
order by 
    PERCENTAGE desc, CODE desc
提出情報
提出日時2022/09/21 20:52:16
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者NoRa
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量99 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
97 MB
データパターン2
AC
99 MB