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

拆出日期部件

简单 08-datetime 日期时间 datetimeextract

把每个订单的下单时间 order_ts 拆成年、月、日、小时四个整数。

  • month 取 1–12,day 取 1–31,hour 取 0–23(24 小时制)。
  • order_ts 为 null 时,四个部件都是 null。

输入

  • orders(order_id, customer_id, order_ts, status, channel),order_ts 不带时区。

输出

列为 order_id, year, month, day, hour,每个订单一行,行顺序不限。

输入表 (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 行

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

#order_idInt64yearInt64monthInt64dayInt64hourInt64
1 1001 2026 1 1 19
2 1002 2026 1 17 14
3 1003 2026 1 8 15
4 1004 2026 5 23 10
5 1005 2026 6 22 11
6 1006 2026 8 15 5
7 1007 2026 6 11 1
8 1008 2026 9 19 20
9 1009 2025 10 5 4
10 1010 2026 2 19 1
11 1011 2026 3 5 3
12 1012 2026 8 1 7
13 1013 2026 1 22 3
14 1014 2026 2 9 1
15 1015 2026 8 3 19
16 1016 2026 2 16 0
17 1017 2025 12 6 4
18 1018 2026 5 19 12
19 1019 2026 2 5 15
20 1020 2025 11 24 11
21 1021 2026 6 29 17
22 1022 2026 6 23 6
23 1023 2026 7 24 2
24 1024 2026 2 26 18
25 1025 2026 7 5 7
26 1026 2025 11 24 8
27 1027 2026 5 22 8
28 1028 2026 1 12 18
29 1029 2026 3 3 14
30 1030 2026 6 12 16
31 1031 2026 2 14 10
32 1032 2026 2 14 13
33 1033 2026 2 14 16
34 1034 2026 2 14 10
35 1035 2025 12 25 18
36 1036 2026 1 16 1
37 1037 2026 3 8 19
38 1038 2025 12 18 9
39 1039 2025 9 12 8
40 1040 2026 2 11 15
41 1041 2026 4 22 15
42 1042 2025 10 28 14
43 1043 2026 1 5 21
44 1044 2026 2 9 18
45 1045 2026 1 23 7
46 1046 2026 6 30 1
47 1047 2026 1 9 9
48 1048 2025 12 14 0
49 1049 2026 7 31 23
50 1050 2026 1 5 17
显示前 50 行,共 200 行