ソースコード
SELECT ROUND(AVG(TOTAL_VALUE)) AS SA_MEDIAN
FROM CONVENIENCE
WHERE TOTAL_VALUE IN (
SELECT 
    CASE WHEN ROW_NUMBER() OVER(
                    ORDER BY TOTAL_VALUE DESC) % 2 = 0
            THEN (
                SELECT 
                    X.TOTAL_VALUE
                FROM (
                    SELECT TOTAL_VALUE
                        ,ROW_NUMBER() OVER(
                            ORDER BY TOTAL_VALUE DESC) AS NUM
                    FROM CONVENIENCE
                    WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND PF_CODE IS NOT NULL
                    ) X
                WHERE X.NUM = ( SELECT COUNT(*) FROM CONVENIENCE WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND PF_CODE IS NOT NULL ) / 2
                    OR X.NUM = ( SELECT COUNT(*) FROM CONVENIENCE WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND PF_CODE IS NOT NULL ) / 2 + 1
                )
          WHEN ROW_NUMBER() OVER(
                    ORDER BY TOTAL_VALUE DESC) % 2 = 1
            THEN (
                SELECT 
                    Y.TOTAL_VALUE
                FROM (
                    SELECT TOTAL_VALUE
                        ,ROW_NUMBER() OVER(
                            ORDER BY TOTAL_VALUE DESC) AS NUM
                    FROM CONVENIENCE
                    WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND PF_CODE IS NOT NULL
                    ) Y
                WHERE Y.NUM = ( SELECT COUNT(*) FROM CONVENIENCE WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND PF_CODE IS NOT NULL ) / 2 + 1
                )
          END AS FLG
FROM CONVENIENCE
WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND PF_CODE IS NOT NULL
)
提出情報
提出日時2022/12/11 23:57:50
コンテスト第4回 SQLコンテスト
問題中央値の算出
受験者S_Katou
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量91 MB
メッセージ
テストケース(通過数/総数)
2/3
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
91 MB
データパターン3
WA
81 MB