ソースコード
WITH
SALES AS (
    SELECT
        PF_CODE,
        TOTAL_VALUE
    FROM
        CONVENIENCE
    WHERE
        SURVEY_YEAR = 2019 AND
        KIND_CODE = '100'
),
STORES AS (
    SELECT
        PF_CODE,
        TOTAL_VALUE
    FROM
        CONVENIENCE
    WHERE
        SURVEY_YEAR = 2019 AND
        KIND_CODE = '150'
),
TOTAL AS (
    SELECT
        NO,
        SUM(SALES) AS TTL_SAL,
        FLOOR(SUM(SALES) / SUM(STORES)) AS AVG_SAL
    FROM (
        SELECT
            (
                RANK() OVER (
                    ORDER BY
                        SALES.TOTAL_VALUE DESC,
                        STORES.TOTAL_VALUE DESC,
                        STORES.PF_CODE ASC
                ) + 2
            ) / 3 AS NO,
            SALES.PF_CODE,
            SALES.TOTAL_VALUE AS SALES,
            STORES.TOTAL_VALUE AS STORES
        FROM
            SALES
        INNER JOIN
            STORES ON
            STORES.PF_CODE = SALES.PF_CODE
    ) AS TOTAL
    GROUP BY
        NO
    ORDER BY
        NO
)
SELECT
    A.NO,
    A.TTL_SAL,
    ROUND(
        A.TTL_SAL * 100.0 /
        (SELECT SUM(B.TTL_SAL) FROM TOTAL AS B),
    1) AS PER_SAL,
    ROUND(
        (SELECT SUM(B.TTL_SAL) FROM TOTAL AS B WHERE B.NO <= A.NO )* 100.0 /
        (SELECT SUM(B.TTL_SAL) FROM TOTAL AS B),
    1) AS CUM_SAL,
    A.AVG_SAL
FROM
    TOTAL AS A
提出情報
提出日時2023/10/14 11:56:20
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者naoigcat
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量77 MB
メッセージ
テストケース(通過数/総数)
2/3
状態
メモリ使用量
データパターン1
AC
76 MB
データパターン2
AC
77 MB
データパターン3
WA
77 MB