コンテストの制限時間が終了しました。
以降も提出を行うことができますが、順位集計には反映されません。
以降も提出を行うことができますが、順位集計には反映されません。
ソースコード
with TBL_AVG as (
select
CATEGORY_CODE
,GENDER_CODE
,AGE
,round(avg(AVERAGE_VALUE),1) as AVG_VAL
from
SCHOOL_HEALTH
where
SURVEY_YEAR=2019
group by 1,2,3
)
,JOIN1 as (
select
S.AGE
,PF_CODE
,S.GENDER_CODE
,S.CATEGORY_CODE
,T.AVG_VAL
,sum(case when AVERAGE_VALUE>=AVG_VAL then 1 else 0 end) as CNT
,count(*) as CNT_ALL
from
SCHOOL_HEALTH S
inner join
TBL_AVG T
on
S.AGE=T.AGE
and S.GENDER_CODE=T.GENDER_CODE
and S.CATEGORY_CODE=T.CATEGORY_CODE
group by 1,2,3,4
)
,JOIN2 as (
select
AGE
,GENDER_CODE
,CATEGORY_CODE
,AVG_VAL
,round(100.0*sum(CNT)/sum(CNT_ALL), 1) as PER
from
JOIN1
group by 1,2,3,4
)
, JOIN3 as (
select
AGE
,GENDER_CODE
,sum(case when CATEGORY_CODE='10' then AVG_VAL end) as H_AVG
,cast(sum(case when CATEGORY_CODE='10' then PER end) as varchar)||'%' as H_PER
,sum(case when CATEGORY_CODE='20' then AVG_VAL end) as W_AVG2
,cast(sum(case when CATEGORY_CODE='20' then PER end) as varchar)||'%' as W_PER
,'test' as test
from
JOIN2
group by 1,2
)
select
AGE
,case
when GENDER_CODE='20' then 'MALE'
when GENDER_CODE='30' then 'FEMALE'
end as GENDER
,case
when substr(cast(H_AVG as varchar), 5,1)='0'
then substr(cast(H_AVG as varchar), 1,3)
else cast(H_AVG as varchar) end as H_AVG
,H_PER
,case
when substr(cast(W_AVG2 as varchar), 4,1)='0'
then substr(cast(W_AVG2 as varchar), 1,2)
else cast(W_AVG2 as varchar)||'' end as W_AVG
,W_PER
from
JOIN3
order by 1 desc, GENDER_CODE desc
提出情報
提出日時 | 2023/08/20 12:58:36 |
コンテスト | 第8回 SQLコンテスト |
問題 | 身長と体重 |
受験者 | 1120011 |
状態 (詳細) | WA (Wrong Answer: 誤答) |
メモリ使用量 | 81 MB |
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
78 MB
データパターン2
WA
81 MB