ソースコード

select 
    s.age as AGE,
    case 
        when s.gender_code='20' then 'MALE' 
        when s.gender_code='30' then 'FEMALE' 
    end as GENDER,
    H_AVG,
    round(
        cast(
            sum(
                case 
                    when category_code='10' and average_value>=h_avg then 1
                end
            )
        as real)
        /cast(H_all as real)*100
    ,1) || '%' as H_PER,
    W_AVG,
    round(
        cast(
            sum(
                case 
                    when category_code='20' and average_value>=w_avg then 1
                end
            )
        as real)
        /cast(w_all as real)*100,1) || '%' as W_PER 
from school_health as S 
inner join (
select 
     AGE,
     gender_code,
     round(
        avg(
            case 
                when category_code='10' then average_value
            end
        )
    ,1) as H_AVG ,
     round(
        avg(
            case 
                when category_code='20' then average_value
            end
        )
    ,1) as W_AVG,
     sum(case when category_code='10' then 1 end) as H_ALL,
     sum(case when category_code='20' then 1 end) as W_ALL
from school_health 
where survey_year=2019 
group by gender_code,age ) as A 
on s.age=a.age and s.gender_code=a.gender_code 
where 
    survey_year=2019 
group by s.age,s.gender_code
order by s.age desc,s.gender_code desc; 
 
提出情報
提出日時2023/09/03 20:31:54
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者kate
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量81 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
76 MB
データパターン2
AC
81 MB