ソースコード
    WITH DATA as (
            select 
                *
            from convenience
            where
               survey_year = 2019
            and kind_code = '100'
            ORDER BY total_value desc
            )
    select
        case
            (
            select 
                count(*) as rowcnt
                from DATA
            ) % 2
        when 0 THEN
            (select 
                round(avg(total_value)) 
            from 
            (
                select 
                    row_number() over win rownum,
                    pf_code, total_value 
                from DATA
                WINDOW win AS (ORDER BY total_value desc)
            ) as tbl
            where 
                rownum IN
                (
                select 
                    (count(*) / 2)
                from DATA
                UNION ALL
                select 
                    (count(*) / 2) + 1
                from DATA
                )
            )
        when 1 THEN
            (select 
                round(avg(total_value)) 
            from 
            (
                select 
                    row_number() over win rownum,
                    pf_code, total_value 
                from DATA
                WINDOW win AS (ORDER BY total_value desc)
            ) as tbl
            where 
                rownum IN
                (
                select 
                    round(count(*) / 2) + 1
                from DATA
                )
            )
        END as SA_MEDIAN
提出情報
提出日時2023/02/16 12:42:15
コンテスト第4回 SQLコンテスト
問題中央値の算出
受験者yakumo
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
78 MB
データパターン3
AC
78 MB