ソースコード
select
    TBL1.PF_CODE as CODE,
    TBL2.PF_NAME as NAME,
    round(sum(
        case when TBL1.col1 = '120' then cast(TBL1.total_AMT as REAL)
        else cast(0 as REAL) end)
        /
    sum(case when TBL1.col1 = '110' then cast(TBL1.total_AMT as REAL)
        else cast(0 as REAL) end
    )*100,1) as PERCENTAGE
from(
    select '110' as col1,PF_CODE,sum(AMT) as total_AMT
    from DRINK_HABITS
    where (GENDER_CODE = '2' or GENDER_CODE = '3') and CATEGORY_CODE = '110'
    group by PF_CODE
    
    union
    
    select '120' as col1,PF_CODE,sum(AMT) as total_AMT
    from DRINK_HABITS
    where (GENDER_CODE = '2' or GENDER_CODE = '3') and CATEGORY_CODE = '120'
    group by PF_CODE
) as TBL1
left outer join PREFECTURE as TBL2 on TBL1.PF_CODE=TBL2.PF_CODE
where total_AMT <> 0
group by TBL1.PF_CODE,TBL2.PF_NAME
order by 3 desc,1 desc
提出情報
提出日時2022/10/25 15:32:47
コンテスト第2回 SQLコンテスト
問題飲酒率
受験者M_ENDO
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
78 MB