ソースコード
with t1 as (
    select total_value,
        row_number() over(order by total_value) as n,
        count(*) over win as n_max
    from convenience
    where survey_year = 2019 and kind_code = '100'
    window win as (order by total_value rows between UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING)
),
t2 as (
    select 
        case when n_max % 2 = 0
            then round(cast(nth_value(total_value, n_max / 2) over win + nth_value(total_value, n_max / 2 + 1) over win as real) / 2.0)
            else nth_value(total_value, n_max / 2 + 1) over win
        end as sm
    from t1
    window win as (order by total_value rows between UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING)
)
select max(sm) as SA_MEDIAN
from t2
提出情報
提出日時2022/12/10 22:04:09
コンテスト第4回 SQLコンテスト
問題中央値の算出
受験者tera_3939
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
78 MB
データパターン3
AC
78 MB