我想按周数或从今天开始的周数来计算保留客户的百分比。列表输出将为 weeknbr-year 以及与自第一次订单以来重新订购的客户百分比相对应的百分比。
customer_tbl 有“account_creation”和“last_ordr_date”) 从今天的角度计算是 今天之前重新订购的客户数量及其第一个订单,除以 21 至 14 天前首次订购的客户数量乘以 100
第一部分对我来说很棘手,因为需要有两个“where”子句以某种方式连接起来以产生保留客户/新客户的单一采用率值。
然后,需要对其进行调整以生成每日列表报告,其中每天都会公开每日重新排序的 custs 计算/每日新的 custs 计算的平均总数
如果有人可以提供指导。这是针对我的餐厅,我正在针对新客户进行促销活动,并希望评估其效果 - 如果这有意义的话。
这是我今天产生新客户和留存客户的起始代码
SELECT
COUNT(*) AS "newcustcount"
FROM
"customers_tbl"
WHERE
DATE ("customers_tbl"."account_creation") BETWEEN DATE('now','localtime','-21 days') AND DATE('now','localtime','-14 days')
UNION
SELECT
COUNT(*) AS "retainedcustcount"
FROM
"customers_tbl"
WHERE
DATE ("customers_tbl"."account_creation") BETWEEN DATE('now','localtime','-21 days') AND DATE('now','localtime','-14 days')
AND DATE("customers_tbl"."last_ordr_date") > DATE ("customers_tbl"."account_creation")
使用子选择:
SELECT 100 * CAST((
SELECT
COUNT(name) AS retainedcustcount
FROM customers_tbl
WHERE DATE (account_creation)
BETWEEN DATE('now','localtime','-21 days')
AND DATE('now','localtime','-14 days')
AND DATE(last_ordr_date)
> DATE (account_creation)
) AS FLOAT) / (
SELECT COUNT(name) AS newcustcount
FROM customers_tbl
WHERE DATE (account_creation)
BETWEEN DATE('now','localtime','-21 days')
AND DATE('now','localtime','-14 days')
)
如果没有 CAST,你只会得到整数除法,即 90% 而不是 90.9090909%。