df-drills pandas · Polars · DuckDB SQL · DuckDB Relational 题目列表 登录

加一个月

中等 08-datetime 日期时间 datetimeoffsetmonth-end

每个订阅从 start_date 开始,期限一个月。求续费日 renew_date = 开始日期加一个自然月(类型为日期)。

  • 一般情况下是下个月的同一天,例如 2026-01-15 → 2026-02-15,2025-12-31 → 2026-01-31(跨年)。
  • 目标月份没有这一天时,取目标月份的最后一天:2024-01-31 → 2024-02-29(闰年),2025-01-31 → 2025-02-28,2025-03-31 → 2025-04-30。
  • 不是“加 30 天”:2024-02-29 → 2024-03-29。
  • start_date 为 null 时 renew_date 为 null。

输入

  • subscriptions(sub_id, start_date),start_date 是日期。

输出

列为 sub_id, renew_date,每个订阅一行,行顺序不限。

输入表 (case base,共 2 个 case:base、month_end)

subscriptions local/base/subscriptions
#sub_idint64start_datedate
1 1 2026-01-15
2 2 2026-02-01
3 3 2026-06-10
4 4 2026-09-28
5 5 2026-11-05
共 5 行

期望输出 (case base,行顺序不限)

#sub_idInt64renew_dateDate
1 1 2026-02-15
2 2 2026-03-01
3 3 2026-07-10
4 4 2026-10-28
5 5 2026-12-05
共 5 行