【发布时间】:2019-08-15 02:49:25
【问题描述】:
我正在使用 Presto SQL 并尝试计算每个按国家和客户状态细分的网站每天登录的客户数量?从“新”到“退货”需要 2 天时间。结果应如下所示:
date country status total_count
2019-08-01 usa new 1
return null
canada new 1
return 1
table a : country of customers
login_date id country
2019-08-01 1 usa
2019-08-01 4 canada
2019-08-01 5 canada
2019-08-02 1 usa
2019-08-02 3 usa
2019-08-02 4 usa
2019-08-03 1 usa
2019-08-03 2 canada
2019-08-03 3 usa
2019-08-03 4 usa
2019-08-03 5 canada
…
table b : daily status of customers.
**It takes 2 days to update the status from ‘new’ to ‘return’
purchase_date id customer_status
2019-08-01 5 return
2019-08-02 4 new
2019-08-02 5 return
2019-08-03 1 return
2019-08-03 2 new
2019-08-03 3 return
2019-08-04 4 return
…
关于如何连接 2 个不同日期的表有什么建议吗?我认为该表应在同一日期加入,并延迟 2 天。
SELECT a.date,
a.country,
b.customer_status,
COUNT(id)
FROM table_a a
LEFT JOIN table_b b
ON (a.id = b.id AND ‘how should I join on date that’s 2 days delay?’)
GROUP BY 1,2
非常感谢!!
【问题讨论】:
-
嗨,我正在使用 Presto SQL