ソースコード
select
    dh.pf_code as CODE,
    pr.pf_name as NAME,
    sum(case when dh.category_code = '120' then dh.amt else 0 end) as every,
    sum(case when dh.category_code = '110' then dh.amt else 0 end) as total
from
    drink_habits as dh
    inner join
        prefecture as pr
        on dh.pf_code = pr.pf_code
where
    dh.gender_code in ('2', '3')
group by
    dh.pf_code;
    
select
    code, name, 
    round(cast(every as real) / cast(total as real) * 100, 1) as PERCENTAGE
from
    (
        select
            dh.pf_code as CODE,
            pr.pf_name as NAME,
            sum(case when dh.category_code = '120' then dh.amt else 0 end) as every,
            sum(case when dh.category_code = '110' then dh.amt else 0 end) as total
        from
            drink_habits as dh
            inner join
                prefecture as pr
                on dh.pf_code = pr.pf_code
        where
            dh.gender_code in ('2', '3')
        group by
            dh.pf_code
    )
order by
    percentage desc, code desc
提出情報
提出日時2023/04/03 22:19:29
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者kanta_phi
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
76 MB