ソースコード

SELECT
    TILE_NO AS 'NO',
    TTL_SAL,
    ROUND (
        TTL_SAL * 100.0 / SUM_ALL,
        1
    ) AS PER_SAL,
    ROUND(
        SUM(TTL_SAL) OVER (
            ORDER BY
                TTL_SAL DESC ROWS UNBOUNDED PRECEDING
        ) * 100.0 / SUM_ALL,
        1
    ) AS CUM_SAL,
    AVG_SAL
FROM
    (
        SELECT
            TILE_NO,
            SUM(SALES_VALUE) AS TTL_SAL,
            SUM(SALES_VALUE) / SUM(STORE_COUNT) AS AVG_SAL,
            (
                SELECT
                    SUM(TOTAL_VALUE)
                FROM
                    CONVENIENCE
                WHERE
                    SURVEY_YEAR = 2019
                    AND KIND_CODE = '100'
            ) AS SUM_ALL
        FROM
            (
                SELECT
                    PF_CODE,
                    SALES_VALUE,
                    STORE_COUNT,
                    NTILE (10) OVER (
                        ORDER BY
                            SALES_VALUE DESC,
                            STORE_COUNT ASC,
                            PF_CODE ASC
                    ) AS TILE_NO
                FROM
                    (
                        SELECT
                            PF_CODE,
                            SALES_VALUE,
                            STORE_COUNT
                        FROM
                            (
                                SELECT
                                    PF_CODE,
                                    TOTAL_VALUE AS SALES_VALUE
                                FROM
                                    CONVENIENCE
                                WHERE
                                    SURVEY_YEAR = 2019
                                    AND KIND_CODE = '100'
                            ) AS A
                            INNER JOIN (
                                SELECT
                                    PF_CODE,
                                    TOTAL_VALUE AS STORE_COUNT
                                FROM
                                    CONVENIENCE
                                WHERE
                                    SURVEY_YEAR = 2019
                                    AND KIND_CODE = '150'
                            ) AS B USING (PF_CODE)
                    )
            )
        GROUP BY
            TILE_NO
    )
ORDER BY
    TILE_NO ASC;
提出情報
提出日時2023/10/14 18:23:55
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者HyperToy
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
76 MB
データパターン2
AC
78 MB
データパターン3
AC
78 MB