ソースコード
WITH t1 AS (
SELECT date(MONTHLY, '+1 month') AS YM,
NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR AS MRR_diff
FROM MRR_DATA
ORDER BY MONTHLY
),
t2 AS(
SELECT * FROM MRR_DATA
FULL JOIN t1
ON MRR_DATA.MONTHLY = t1.YM
)
SELECT
*
--a.YM,
--sum(
--    CASE 
--        WHEN a.MRR_diff IS null THEN 0
--        ELSE a.MRR_diff
--    END
--    ) as MRR 
FROM t2 as a
JOIN t2 as b
ON
a.YM >= b.YM
GROUP BY a.YM

;
WITH t1 AS (
SELECT date(MONTHLY, '+1 month') AS YM,
NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR AS MRR_diff
FROM MRR_DATA
ORDER BY MONTHLY
),
t2 AS(
SELECT * FROM MRR_DATA
FULL JOIN t1
ON MRR_DATA.MONTHLY = t1.YM
),
t3 AS (SELECT 
MONTHLY,
CASE 
    WHEN t2.MRR_diff IS NULL THEN 0
    ELSE t2.MRR_diff
END AS MRR_diff
FROM t2
WHERE MONTHLY IS NOT NULL
ORDER BY MONTHLY)
SELECT a.MONTHLY AS YM, 
--b.MRR_diff
SUM(b.MRR_diff) AS MRR
FROM t3 as a
JOIN t3 as b
ON a.MONTHLY >= b.MONTHLY 
GROUP BY YM
ORDER BY YM
提出情報
提出日時2023/02/19 22:52:11
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者matsushiman
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量90 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
90 MB
データパターン2
WA
85 MB
データパターン3
WA
81 MB