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

两期都活跃

中等 12-setops 集合运算与拼接 intersectset-semanticsdistinct

找出在 2026 年 9 月和 2026 年 10 月都有事件的用户。

  • 9 月指 ts 落在 [2026-09-01 00:00:00, 2026-10-01 00:00:00),10 月指 ts 落在 [2026-10-01 00:00:00, 2026-11-01 00:00:00)(左闭右开)。
  • 任何事件类型都算活跃。
  • 结果去重:每个 user_id 只出现一次,不管他在两个月里各有多少条事件。
  • 没有符合条件的用户时,输出空表。

输入

  • events(event_id, user_id, ts, event_type, page)

输出

只有一列 user_id,行顺序不限。

输入表 (case base,共 3 个 case:base、dups、none)

events web/events
#event_idint64user_idint64tsdatetimeevent_typestringpagestring
1 1 53 2026-06-03 17:57:33 login /home
2 2 53 2026-06-04 15:21:00 visit /home
3 3 53 2026-06-04 15:22:00 view /product/303
4 4 53 2026-06-04 15:32:04 add_to_cart /cart
5 5 56 2026-06-05 23:24:19 login /home
6 6 56 2026-06-05 23:29:18 view /product/202
7 7 56 2026-06-05 23:36:15 view /product/202
8 8 56 2026-06-05 23:47:36 add_to_cart /cart
9 9 56 2026-06-05 23:56:24 checkout /checkout
10 10 56 2026-06-06 19:14:00 visit /home
11 11 56 2026-06-06 19:22:53 view /product/303
12 12 56 2026-06-06 19:25:12 view /home
13 13 56 2026-06-06 19:28:25 add_to_cart /cart
14 14 29 2026-06-07 10:40:01 login /home
15 15 29 2026-06-07 10:46:43 view /product/303
16 16 29 2026-06-07 11:04:46 add_to_cart /cart
17 17 29 2026-06-07 11:09:25 checkout /checkout
18 18 34 2026-06-07 12:57:49 login /home
19 19 34 2026-06-07 13:03:57 view /product/202
20 20 34 2026-06-07 13:11:07 view /home
显示前 20 行,共 1500 行

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

#user_idInt64
1 22
2 32
3 17
4 47
5 39
6 50
7 55
8 10
9 28
10 31
11 30
12 26
13 60
14 42
15 11
16 15
17 14
18 5
19 52
20 9
21 16
22 27
23 38
24 20
25 8
26 7
27 4
28 33
29 36
30 21
31 23
32 48
33 3
34 46
35 13
共 35 行