コンテストの制限時間が終了しました。
以降も提出を行うことができますが、順位集計には反映されません。
以降も提出を行うことができますが、順位集計には反映されません。
ソースコード
with s as (select * from school_health where survey_year = 2019)
, sw as (
select * from s
where CATEGORY_CODE = 20
)
, sh as (
select * from s
where CATEGORY_CODE = 10
)
, swa as (
select
AGE
, GENDER_CODE
, ROUND(avg(AVERAGE_VALUE), 1) as WA
, COUNT(1) as CNT
from sw
group by AGE, GENDER_CODE
)
, sha as (
select
AGE
, GENDER_CODE
, ROUND(avg(AVERAGE_VALUE), 1) as HA
, COUNT(1) as CNT
from sh
group by AGE, GENDER_CODE
)
, swap as (
select
sw.AGE as AGE
, sw.GENDER_CODE as GENDER_CODE
, swa.WA as WA
, swa.CNT as CNT
, count(case when sw.AVERAGE_VALUE >= swa.WA then 1 end) as OCNT
from sw join swa on sw.GENDER_CODE = swa.GENDER_CODE and sw.AGE = swa.AGE
group by sw.GENDER_CODE, sw.AGE
)
, swap2 as (
select *, ROUND(100.0 * OCNT / CNT, 1) as W_PER from swap
)
, shap as (
select
sh.AGE as AGE
, sh.GENDER_CODE as GENDER_CODE
, sha.HA as HA
, sha.CNT as CNT
, count(case when sh.AVERAGE_VALUE >= sha.HA then 1 end) as OCNT
from sh join sha on sh.GENDER_CODE = sha.GENDER_CODE and sh.AGE = sha.AGE
group by sh.GENDER_CODE, sh.AGE
)
, shap2 as (
select *, ROUND(100.0 * OCNT / CNT, 1) as H_PER from shap
)
select
shap2.AGE as AGE
, case shap2.GENDER_CODE when 20 then 'MALE' else 'FEMALE' end as GENDER
, shap2.HA as H_AVG
, shap2.H_PER || '%' as H_PER
, swap2.WA as W_AVG
, swap2.W_PER || '%' as W_PER
from shap2 join swap2 on shap2.AGE = swap2.AGE and shap2.GENDER_CODE = swap2.GENDER_CODE
order by AGE desc, shap2.GENDER_CODE desc
提出情報
提出日時 | 2024/05/04 19:28:04 |
コンテスト | 第8回 SQLコンテスト |
問題 | 身長と体重 |
受験者 | daku10 |
状態 (詳細) | AC (Accepted: 正答) |
メモリ使用量 | 88 MB |
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
88 MB