ソースコード
WITH target AS (
	SELECT
	    TOTAL_VALUE
	  , count(*) over() as c
	FROM
	    CONVENIENCE
	WHERE
	    SURVEY_YEAR = 2019
	AND KIND_CODE   = '100'
)
, odd AS (
    SELECT DISTINCT
        c
      , nth_value(TOTAL_VALUE, (c+1)/2) OVER(RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)   AS SA_MEDIAN
    FROM
        target
)
, even AS (
    SELECT DISTINCT
        c
      , (
             nth_value(TOTAL_VALUE, c/2  ) OVER(RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
           + nth_value(TOTAL_VALUE, c/2+1) OVER(RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
        ) / 2 AS SA_MEDIAN
    FROM
        target
)
SELECT
    iif(odd.c % 2 = 1, odd.SA_MEDIAN, even.SA_MEDIAN) AS SA_MEDIAN
FROM
    odd, even
;
提出情報
提出日時2022/12/12 10:20:39
コンテスト第4回 SQLコンテスト
問題中央値の算出
受験者kamaoda
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量93 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
79 MB
データパターン2
WA
93 MB
データパターン3
WA
84 MB