【发布时间】:2021-03-15 20:18:45
【问题描述】:
我有一个包含以下字段的表格:
| order_id | order_date | customer_id | second_highest_order_date_of_the_customer
| 12345 | 2020-11-01 | customer_ABC | 2020-05-01
| 67891 | 2020-05-01 | customer_ABC | 2020-02-01
| 00531 | 2020-02-01 | customer_ABC | 2020-01-01
| 00789 | 2020-01-01 | customer_ABC |
我发现很难在 SQL 中计算 second_highest_order_date_of_the_customer 列。 我可以使用窗口函数计算每个客户整体的第二高日期,但我很难在订单级别找到 second_highest_date,它不应该超过所述行中的 order_date。
非常感谢任何帮助
【问题讨论】:
标签: sql datatable aggregate-functions window-functions presto