ソースコード
WITH STORE_DTL AS(
    SELECT
        PF_CODE
        ,MAX(CASE WHEN KIND_CODE = '100' THEN TOTAL_VALUE END) AS REVENUE
        ,MAX(CASE WHEN KIND_CODE = '150' THEN TOTAL_VALUE END) AS STORE
    FROM
        CONVENIENCE
    WHERE
        SURVEY_YEAR = 2019
    GROUP BY
        PF_CODE
    ORDER BY
        REVENUE DESC
        ,STORE ASC
        ,PF_CODE ASC
), GROUP_NO_TBL AS(
    SELECT
        *
        ,(ROW_NUMBER() OVER() + 2) / 3 AS GROUP_NO
    FROM
        STORE_DTL
), GROUP_DTL AS(
SELECT
    GROUP_NO
    ,SUM(REVENUE) AS REVENUE
    ,SUM(STORE) AS STORE
FROM
    GROUP_NO_TBL
GROUP BY
    GROUP_NO
)
SELECT
    GROUP_NO AS NO
    ,REVENUE AS TTL_SAL
    ,ROUND(100.0 * REVENUE / SUM(REVENUE) OVER(), 1) AS PER_SAL
    ,ROUND(100.0 * SUM(REVENUE) OVER(ORDER BY GROUP_NO) / SUM(REVENUE) OVER(), 1) AS CUM_SAL
    ,REVENUE / STORE AS AVG_SAL
FROM
    GROUP_DTL
ORDER BY
    NO
提出情報
提出日時2024/03/11 19:38:17
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者citrus_sudachi
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量83 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
83 MB
データパターン2
AC
83 MB
データパターン3
AC
83 MB