ソースコード
WITH PF_DATA AS (
SELECT
    PF_CODE,
    SUM(
        CASE
            WHEN KIND_CODE = 100 THEN TOTAL_VALUE
            ELSE 0
        END
    ) AS SALES_AMT,
    SUM(
        CASE
            WHEN KIND_CODE = 150 THEN TOTAL_VALUE
            ELSE 0
        END
    ) AS STORES_AMT
FROM
    CONVENIENCE
WHERE
    SURVEY_YEAR = 2019
GROUP BY 1
), GROUPS AS (
SELECT
    (ROW_NUMBER() OVER(ORDER BY SALES_AMT DESC, STORES_AMT, PF_CODE) + 2) / 3 AS GROUP_NO,
    PF_CODE,
    SALES_AMT,
    STORES_AMT
FROM
    PF_DATA
), GROUP_TOTAL AS (
SELECT
    GROUP_NO,
    SUM(SALES_AMT) AS SALES_SUM,
    SUM(STORES_AMT) AS STORES_SUM
FROM
    GROUPS
GROUP BY 1
), TOTAL AS (
SELECT
    SUM(SALES_SUM) AS SALES_TTL
FROM
    GROUP_TOTAL
)
SELECT
    A.GROUP_NO AS NO,
    A.SALES_SUM AS TTL_SAL,
    ROUND(100.0 * A.SALES_SUM / TOTAL.SALES_TTL, 1) AS PER_SAL,
    ROUND(100.0 * SUM(B.SALES_SUM) / TOTAL.SALES_TTL, 1) AS CUM_SAL,
    A.SALES_SUM / A.STORES_SUM AS AVG_SAL
FROM GROUP_TOTAL A, TOTAL
INNER JOIN GROUP_TOTAL B ON (A.GROUP_NO >= B.GROUP_NO)
GROUP BY 1
ORDER BY 1
提出情報
提出日時2023/12/17 14:48:08
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者hiffy12
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB
データパターン3
AC
84 MB