ソースコード
with hs22 as(
    select
        aa.AREA_CODE as CODE,
        aa.AREA_NAME as NAME,
        dense_rank() over (ORDER BY round((cast(hs.FOOD_EXP as real)/cast(hs.CONSUMPTION_EXP as real)) * 100,1) ASC) as rank,
        round((cast(hs.FOOD_EXP as real)/cast(hs.CONSUMPTION_EXP as real)) * 100,1) || '%' as ratio
    from HOUSEHOLD_SURVEY as hs
    inner join AREA as aa on hs.AREA_CODE = aa.AREA_CODE
    where SURVEY_YEAR = 2022
),hs17 as (
    select
        aa.AREA_CODE as CODE,
        aa.AREA_NAME as NAME,
        dense_rank() over (ORDER BY round((cast(hs.FOOD_EXP as real)/cast(hs.CONSUMPTION_EXP as real)) * 100,1) ASC) as rank,
        round((cast(hs.FOOD_EXP as real)/cast(hs.CONSUMPTION_EXP as real)) * 100,1) || '%' as ratio
    from HOUSEHOLD_SURVEY as hs
    inner join AREA as aa on hs.AREA_CODE = aa.AREA_CODE
    where SURVEY_YEAR = 2017
),hs12 as (
    select
        aa.AREA_CODE as CODE,
        aa.AREA_NAME as NAME,
        dense_rank() over (ORDER BY round((cast(hs.FOOD_EXP as real)/cast(hs.CONSUMPTION_EXP as real)) * 100,1) ASC) as rank,
        round((cast(hs.FOOD_EXP as real)/cast(hs.CONSUMPTION_EXP as real)) * 100,1) || '%' as ratio
    from HOUSEHOLD_SURVEY as hs
    inner join AREA as aa on hs.AREA_CODE = aa.AREA_CODE
    where SURVEY_YEAR = 2012
)
select 
    aa.AREA_CODE as CODE,
    aa.AREA_NAME as NAME,
    hs22.rank as '2022_RANK',
    hs22.ratio as '2022_RATIO',
    hs17.rank as '2017_RANK',
    hs17.ratio as '2017_RATIO',
    hs12.rank as '2012_RANK',
    hs12.ratio as '2012_RATIO'
from AREA as aa
inner join hs22 on aa.AREA_CODE = hs22.CODE
inner join hs17 on aa.AREA_CODE = hs17.CODE
inner join hs12 on aa.AREA_CODE = hs12.CODE
order by
    hs22.rank asc,
    CODE desc;    
提出情報
提出日時2024/07/22 13:06:08
コンテスト第10回 SQLコンテスト
問題食料費の割合
受験者T.M
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB
データパターン3
AC
85 MB