有人能帮我做以下事情吗。我需要计算客户第一次和第二次购买的平均日差:
我有以下几点:有人能帮助我的问题吗。
SELECT src.id, AVG(DATEDIFF(dest.purchasing, src.registrations)) AS avgdays FROM
(SELECT accounts.id, accounts.`created_date` AS registrations FROM accounts
WHERE YEAR(accounts.`created_date`) =2018 AND MONTH(accounts.`created_date`) =4) src
INNER JOIN
(SELECT account_id, MIN(created_date) AS purchasing
FROM ordering
WHERE STATUS = 'Fulfilled'
GROUP BY account_id
) dest
ON
dest.account_id = src.id;
1条答案
按热度按时间thtygnil1#
如果客户注册日期也是他的第一个订单购买日期,下面的查询将为您提供第二次购买之间的平均差异。