【发布时间】:2021-09-28 18:49:33
【问题描述】:
我正在尝试通过相同的用户 ID 对 Event_1 和 Event_2 进行左连接,并到最大的前一个日期。
事件_1
| timestamp | user_id | n_trigg |
|-------------------------|---------|---------|
| 2021-04-24 15:39:51.667 | 1213 | 1 |
| 2021-04-24 15:40:13.631 | 1213 | 2 |
| 2021-04-24 18:51:22.651 | 1213 | 3 |
Event_2(发生在 Event_1 之后)
| timestamp | user_id | product_id |
|-----------------------|---------|------------|
|2021-04-24 15:39:56.483| 1213 | 11313 |
|2021-04-24 15:40:14.775| 1213 | 11313 |
我想得到以下结果:
| timestamp_event_1 | user_id | n_trigg | timestamp_event_2 | product_id |
|---|---|---|---|---|
| 2021-04-24 15:39:51.667 | 1213 | 1 | 2021-04-24 15:39:56.483 | 11313 |
| 2021-04-24 15:40:13.631 | 1213 | 2 | 2021-04-24 15:40:14.775 | 11313 |
我已经尝试过了,但它不适用于 Redshift:
SELECT *
FROM Event_1 LEFT JOIN Event_2 ON Event_1.user_id = Event_2.user_id
AND Event_2.timestamp = (select min(timestamp) from Event_2
where Event_2.user_id=Event_1.user_id
and Event_2.timestamp > Event_1.timestamp)
但我收到以下错误:
ERROR: This type of correlated subquery pattern is not supported yet
提前非常感谢您。 使用 Redshift 1.0.29551
【问题讨论】:
标签: sql subquery amazon-redshift correlated-subquery