ソースコード
WITH TMP AS(
  SELECT
    PF_CODE,
    TOTAL_VALUE AS SALES_VALUE
  FROM
    CONVENIENCE
  WHERE
    SURVEY_YEAR = 2019
  AND KIND_CODE = '100'
),
TMP2 AS(
  SELECT
    PF_CODE,
    TOTAL_VALUE AS TENANT_VALUE
  FROM
    CONVENIENCE
  WHERE
    SURVEY_YEAR = 2019
  AND KIND_CODE = '150'
),
TMP3 AS(
  SELECT
    (ROW_NUMBER() OVER(ORDER BY SALES_VALUE DESC, TENANT_VALUE ASC, PF_CODE ASC) + 2) / 3 AS GROUP_NO,
    PF_CODE,
    SALES_VALUE,
    TENANT_VALUE
  FROM
    TMP
    INNER JOIN
      TMP2
    USING
      (PF_CODE)
),
TMP4 AS(
  SELECT
    SUM(TOTAL_VALUE) AS SUM_SAL
  FROM
    CONVENIENCE
  WHERE
    SURVEY_YEAR = 2019
  AND KIND_CODE = '100'
)
SELECT
  ROW_NUMBER() OVER(ORDER BY GROUP_NO) AS NO,
  SUM(SALES_VALUE) AS TTL_SAL,
  ROUND(100.0 * SUM(SALES_VALUE) / TMP4.SUM_SAL, 1) AS PER_SAL,
  ROUND(100.0 * SUM(SUM(SALES_VALUE)) OVER(ORDER BY GROUP_NO) / TMP4.SUM_SAL, 1) AS CUM_SAL,
  FLOOR(CAST(SUM(SALES_VALUE) AS REAL) / SUM(TENANT_VALUE)) AS AVG_SAL
FROM
  TMP3,
  TMP4
GROUP BY
  GROUP_NO
提出情報
提出日時2023/10/22 18:20:13
コンテスト第9回 SQLコンテスト
問題販売額分析
受験者hiffy12
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量75 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
75 MB
データパターン2
AC
74 MB
データパターン3
AC
75 MB