ソースコード
WITH D AS (SELECT MIN(MONTHLY) MINMO, MAX(MONTHLY) MAXMO FROM MRR_DATA),
calendar AS (
    SELECT MINMO AS calendar_date FROM D
    UNION ALL
    SELECT
        DATE(calendar_date, '+1 month') AS calendar_date
    FROM calendar
    WHERE
        calendar_date <= (SELECT MAXMO FROM D)
),
T AS (SELECT C.calendar_date MONTHLY, ifnull(NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR, 0) MRR, ROW_NUMBER() OVER(ORDER BY C.calendar_date) RAN FROM calendar c left join MRR_DATA M on C.calendar_date = M.MONTHLY),
 M AS (SELECT MONTHLY YM, lag(MRR, 1, 0) OVER (ORDER BY RAN) MRR, RAN FROM T)
SELECT M1.YM, (SELECT SUM(MRR) FROM M M2 WHERE M2.RAN <= M1.RAN) MRR
FROM M M1
ORDER BY 1
提出情報
提出日時2023/02/17 18:27:03
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者mine
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量82 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
80 MB
データパターン3
AC
82 MB