ソースコード
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 TOTAL_VALUE > 0
                    ) X
                WHERE X.NUM = ( SELECT COUNT(*) FROM CONVENIENCE WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND TOTAL_VALUE > 0 ) / 2
                    OR X.NUM = ( SELECT COUNT(*) FROM CONVENIENCE WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND TOTAL_VALUE > 0 ) / 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 TOTAL_VALUE > 0
                    ) Y
                WHERE Y.NUM = ( SELECT COUNT(*) FROM CONVENIENCE WHERE SURVEY_YEAR = 2019 AND KIND_CODE = '100' AND TOTAL_VALUE > 0 ) / 2 + 1
                )
          END AS FLG
FROM CONVENIENCE
WHERE SURVEY_YEAR = 2019
    AND KIND_CODE = '100' AND TOTAL_VALUE > 0
)
提出情報
提出日時2022/12/11 23:47:31
コンテスト第4回 SQLコンテスト
問題中央値の算出
受験者S_Katou
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
80 MB
データパターン2
WA
88 MB
データパターン3
WA
88 MB