ソースコード
select 
    H.AGE, 
    CASE  
        WHEN H.GENDER_CODE = '20' THEN 'MALE' 
        ELSE 'FEMALE' 
    END AS GENDER,
    H.H_AVG,
    H.H_PER,
    W.W_AVG,
    W.W_PER
from
(
select SH.AGE,
    SH.GENDER_CODE, T1.H_AVG, ROUND(CAST(COUNT(SH.PF_CODE) AS REAL) / T1.CNT * 100, 1)||'%' as H_PER
from SCHOOL_HEALTH AS SH inner join (
-- 身長の平均
select 
    AGE, 
    GENDER_CODE, 
    ROUND(AVG(AVERAGE_VALUE),1) AS H_AVG,
    COUNT(PF_CODE) AS CNT from SCHOOL_HEALTH
where SURVEY_YEAR  = 2019 and CATEGORY_CODE = '10'
group by GENDER_CODE, AGE, CATEGORY_CODE) AS T1
 on SH.AGE = T1.AGE and SH.GENDER_CODE = T1.GENDER_CODE and SH.CATEGORY_CODE = '10'
where SH.AVERAGE_VALUE >= T1.H_AVG
group by SH.AGE, SH.GENDER_CODE
order by SH.AGE desc, SH.GENDER_CODE desc
) H inner join 
(
select SH.AGE,
    SH.GENDER_CODE, T1.H_AVG as W_AVG, ROUND(CAST(COUNT(SH.PF_CODE) AS REAL) / T1.CNT * 100, 1)||'%' as W_PER
from SCHOOL_HEALTH AS SH inner join (
-- 身長の平均
select 
    AGE, 
    GENDER_CODE, 
    ROUND(AVG(AVERAGE_VALUE),1) AS H_AVG,
    COUNT(PF_CODE) AS CNT from SCHOOL_HEALTH
where SURVEY_YEAR  = 2019 and CATEGORY_CODE = '20'
group by GENDER_CODE, AGE, CATEGORY_CODE) AS T1
 on SH.AGE = T1.AGE and SH.GENDER_CODE = T1.GENDER_CODE and SH.CATEGORY_CODE = '20'
where SH.AVERAGE_VALUE >= T1.H_AVG
group by SH.AGE, SH.GENDER_CODE
order by SH.AGE desc, SH.GENDER_CODE desc
) W on H.AGE = W.AGE and H.GENDER_CODE = W.GENDER_CODE
提出情報
提出日時2023/08/19 22:29:50
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者neve_neve
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
77 MB
データパターン2
WA
82 MB