ソースコード
WITH tmp_table AS (
    SELECT 
        SURVEY_YEAR
        ,PF_CODE
        ,GENDER_CODE
        ,AGE
        ,CASE WHEN CATEGORY_CODE = 10 THEN AVERAGE_VALUE END AS Height
        ,CASE WHEN CATEGORY_CODE = 20 THEN AVERAGE_VALUE END AS Weight
    FROM SCHOOL_HEALTH
    WHERE SURVEY_YEAR = 2019
),AVG_table AS (
    SELECT
        AGE
        ,GENDER_CODE
        ,CASE WHEN GENDER_CODE = 20 THEN 'MALE' WHEN GENDER_CODE = 30 THEN 'FEMALE' END AS GENDER
        ,ROUND(AVG(Height),1) AS H_AVG
        ,ROUND(AVG(Weight),1) AS W_AVG
        ,COUNT(ROUND(AVG(Height),1)/10 AS H_PER
--        ,ROUND(SUM(CASE WHEN PF_AVERAGE >= ALL_AVERAGE THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 1) || '%' AS PER
        --,Weight
    FROM tmp_table
    WHERE Height is not null or Weight is not null
    GROUP BY AGE,GENDER_CODE,GENDER
)

SELECT * FROM AVG_table
ORDER BY AGE Desc,GENDER_CODE Desc
提出情報
提出日時2023/08/22 17:29:41
コンテスト第8回 SQLコンテスト
問題身長と体重
受験者aiueo
状態 (詳細)RE
(Runtime Error: 実行時エラー)
メモリ使用量89 MB
メッセージ
SQLITE_ERROR: near "AS": syntax error
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
RE
80 MB
データパターン2
RE
89 MB