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

周汇总

中等 19-timeseries 时间序列 resampleweektime-seriestruncate

按周汇总已支付订单的销售情况。

  • 只统计 status = 'paid' 的订单;订单所在的周由 order_ts 决定。
  • 一周从周一 00:00:00 开始,到周日 23:59:59.999999 结束,用该周周一的日期作为 week_start(date 类型)。
  • n_orders:该周的订单数(不同 order_id 的个数)。
  • revenue:该周所有订单行 qty * unit_price * (1 - discount) 之和,discount 为 null 按 0 算。
  • 没有已支付订单的周不输出。

输入

  • orders(order_id, customer_id, order_ts, status, channel)
  • order_items(order_id, product_id, qty, unit_price, discount)

输出

列为 week_start, n_orders, revenue,按 week_start 升序排列。

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

orders shop/orders
#order_idint64customer_idint64order_tsdatetimestatusstringchannelstring
1 1001 39 2026-01-01 19:38:00 paid app
2 1002 16 2026-01-17 14:07:00 paid app
3 1003 4 2026-01-08 15:40:20 cancelled web
4 1004 2 2026-05-23 10:48:58 paid null
5 1005 12 2026-06-22 11:07:22 paid store
6 1006 17 2026-08-15 05:15:25 paid web
7 1007 9 2026-06-11 01:00:32 refunded store
8 1008 45 2026-09-19 20:47:10 paid web
9 1009 2 2025-10-05 04:53:38 paid app
10 1010 4 2026-02-19 01:39:54 paid app
11 1011 28 2026-03-05 03:04:45 refunded store
12 1012 2 2026-08-01 07:09:17 paid web
13 1013 26 2026-01-22 03:48:14 refunded store
14 1014 2 2026-02-09 01:41:41 paid app
15 1015 5 2026-08-03 19:49:04 refunded web
16 1016 26 2026-02-16 00:43:43 refunded app
17 1017 9 2025-12-06 04:48:57 pending app
18 1018 999 2026-05-19 12:13:43 paid store
19 1019 26 2026-02-05 15:02:26 paid store
20 1020 44 2025-11-24 11:19:00 cancelled web
显示前 20 行,共 200 行
order_items shop/order_items
#order_idint64product_idint64qtyint64unit_pricefloat64discountfloat64
1 1001 22 3 298.8 null
2 1001 26 1 190.0 0.1
3 1002 6 2 254.2 0.0
4 1002 9 3 79.0 null
5 1002 19 5 305.1 0.2
6 1003 9 2 79.0 0.1
7 1003 28 2 47.4 0.0
8 1004 5 1 500.0 0.1
9 1005 3 1 89.0 0.0
10 1005 12 4 45.0 null
11 1006 13 1 19.9 0.1
12 1006 25 2 39.9 null
13 1007 27 1 12.5 null
14 1008 3 1 89.0 null
15 1008 16 1 29.9 null
16 1008 17 1 129.0 null
17 1009 2 1 49.9 0.0
18 1009 10 2 42.5 null
19 1009 20 1 84.5 0.05
20 1010 1 1 23.8 0.1
显示前 20 行,共 500 行

期望输出 (case base,行顺序要一致)

#week_startDaten_ordersInt64revenueFloat64
1 2025-08-11 2 3801.57
2 2025-08-18 1 161.1
3 2025-08-25 1 430.8
4 2025-09-08 1 21.51
5 2025-09-22 2 482.705
6 2025-09-29 3 1348.525
7 2025-11-17 2 2338.145
8 2025-11-24 3 1287.91
9 2025-12-01 3 587.805
10 2025-12-08 4 1553.465
11 2025-12-15 4 1434.35
12 2025-12-22 2 1439.76
13 2025-12-29 3 1396.22
14 2026-01-05 5 2005.29
15 2026-01-12 5 3151.895
16 2026-01-19 2 1677.88
17 2026-01-26 4 2541.38
18 2026-02-02 2 1032.32
19 2026-02-09 8 4011.05
20 2026-02-16 2 1350.77
21 2026-02-23 3 1664.72
22 2026-03-02 2 941.05
23 2026-03-09 1 211.175
24 2026-03-16 1 72.0
25 2026-03-30 3 2013.92
26 2026-04-06 1 523.21
27 2026-04-13 2 532.11
28 2026-04-20 1 400.92
29 2026-04-27 3 4292.155
30 2026-05-04 2 1058.02
31 2026-05-11 2 839.705
32 2026-05-18 5 2560.09
33 2026-05-25 2 1108.37
34 2026-06-01 3 1640.6
35 2026-06-08 3 688.82
36 2026-06-15 1 134.01
37 2026-06-22 2 396.94
38 2026-06-29 2 264.72
39 2026-07-06 4 1816.05
40 2026-07-13 1 430.1
41 2026-07-20 3 2405.32
42 2026-07-27 3 802.975
43 2026-08-03 1 1345.5
44 2026-08-10 2 226.71
45 2026-08-17 1 368.705
46 2026-08-24 2 1232.23
47 2026-08-31 2 1667.0
48 2026-09-07 2 1332.0
49 2026-09-14 1 247.9
50 2026-09-21 1 1415.22
显示前 50 行,共 51 行