SQL查询在过去的N天中获取点击/购买的物品,并获得过去的活动

发布于 2025-02-01 08:12:15 字数 1545 浏览 3 评论 0原文

我试图弄清楚如何编写SQL查询以构建所述的数据集如下:

提取在过去49天内单击的项目以构建目标项目以及在单击目标项目之前发生的相应点击行为。以一个目标项目 a 为例,我们设置了将 a 单击为最后一天的一天以及该用户在过去14天中采取的行为。

这是我要查询的表示例:

  • user_id
  • item_id
  • action(单击,购买)
  • 时间戳
用户ID项目IDActionTime_stamp
12单击2022-03-02 002 00:00:00
13单击2022-03-03-02 002 002 002 002 :10:00
14单击2022-03-02 00:12:00
29单击2022-03-02-02 00:01:00
211单击2022-03-02-02-02 00:08:00
23单击2022-03- 02 00:12:00
22单击2022-03-02 00:14:00
24单击2022-03-02-02 00:18:00

结果应该看起来像这样的结果:

用户ID项目ID
12
13
1 44
29
211
23
22
24

每个用户的最后一项ID是目标项目,其余的user_id/item_id对订购了WRT Time_stamp。

谢谢

I'm trying to figure out how to write an SQL query to build the dataset described as follows:

Extract items that were clicked in the past 49 days to construct the target items and the corresponding click behaviors that happened before the target items were clicked. Using one target item a as an example, we set the day that a is clicked as the last day and the behaviors that this user took in the past 14 days.

Here's a sample of the table that I'm querying from:

  • user_id
  • item_id
  • action (click, purchased)
  • timestamp
user iditem idactiontime_stamp
12click2022-03-02 00:00:00
13click2022-03-02 00:10:00
14click2022-03-02 00:12:00
29click2022-03-02 00:01:00
211click2022-03-02 00:08:00
23click2022-03-02 00:12:00
22click2022-03-02 00:14:00
24click2022-03-02 00:18:00

The result should look something like this:

user iditem id
12
13
14
29
211
23
22
24

where the last item id for each user is the target item and the remaining user_id/item_id pairs are ordered w.r.t time_stamp.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文