ソースコード
WITH T1 AS(
    SELECT
        SUM(
            CASE KIND_CODE
                WHEN '100' THEN TOTAL_VALUE
                ELSE 0
            END
        ) AS TTL_SAL,
        SUM(
            CASE KIND_CODE
                WHEN '150' THEN TOTAL_VALUE
                ELSE 0
            END
        ) AS TTL_SHP,
        PF_CODE
    FROM
        CONVENIENCE
    WHERE
        SURVEY_YEAR = 2019
    GROUP BY
        PF_CODE
),
T2 AS(
    SELECT
        TTL_SAL,
        TTL_SHP,
        (RANK() OVER(ORDER BY TTL_SAL DESC, TTL_SHP ASC, PF_CODE ASC) + 2) / 3 AS NO
    FROM
        T1
),
T3 AS(
    SELECT
        SUM(TTL_SAL) AS TTL_SAL,
        SUM(TTL_SAL) / SUM(TTL_SHP) AS AVG_SAL,
        NO
    FROM
        T2
    GROUP BY
        NO
)
SELECT
    T3.NO,
    T3.TTL_SAL,
    T3.AVG_SAL,
    ROUND(100.0 * T3.TTL_SAL / SUM(MT3.TTL_SAL), 1) AS PER_SAL,
    ROUND(
        100.0 * SUM(
            CASE
                WHEN MT3.NO <= T3.NO THEN MT3.TTL_SAL
                ELSE 0
            END
        ) / SUM(
            MT3.TTL_SAL
        ), 1
    ) AS CUM_SAL
FROM
    T3
CROSS JOIN
    T3 AS MT3
GROUP BY
    T3.NO
ORDER BY
    T3.NO
提出情報
提出日時2023/12/14 23:27:00
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者tokusakurai
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
86 MB
データパターン3
AC
85 MB