I have a table like this:
<表类=“s-表”> <标题>Track all user emails, IPs, dates/times and events (registrations and purchases).
Right now, I'm trying to get daily statistics on a) signups and b) conversions (purchases that occur within 7 days of signup, the original signup date assigned to that email/IP, not the purchase date). p>
I could easily figure out a) registrations... but trying to figure out how to query conversions within 7 days and then assign each registration conversion to the registration date (instead of the conversion date, which is easy), it turns out this It's quite a challenge.
This is my query so far:
选择日期(时间戳)作为日期, SUM(CASE WHEN event = '注册' THEN 1 ELSE 0 END) AS 注册, SUM(CASE WHEN event = '购买' THEN 1 ELSE 0 END) AS 转化 来自点击跟踪 哪里日期(时间戳)<='2021-07-31' 和日期(时间戳)>='2021-07-01' 按日期分组 按日期排序
This gives me the following results:
<表类=“s-表”> <标题>What I ideally need is something like this (3 purchase events associated with 3 registration events on the 15th, hence why 3 conversions are assigned to the 15th and none to the 16th):
<表类=“s-表”> <标题>Does it make sense?
Keep in mind that the size of this click_tracking table is a million or two records, and I've tried JOINS on it multiple times to make it crash, so not just any query will work...
Any idea how to solve this problem efficiently and change my query to accomplish this task?
You need window functions to perform this kind of query: