您好我正在计算CRentention并且我想计算1天,3天和7天的保留期,但我已经提出了三个查询,有人可以告诉我如何在一个查询中编写您。 请帮忙!
答案 0 :(得分:1)
组合多个查询的简单方法通常是连接。如果您将每个查询都转换为子查询,然后按日期加入,则应该为您提供所需的结果。
如:
SELECT one_day.activity_date as activity_date,
one_day.signed_up_users, one_day.logged_in_users, one_day.retention_pct,
three_day.signed_up_users, three_day.logged_in_users, three_day.retention_pct,
seven_day.signed_up_users, seven_day.logged_in_users, seven_day.retention_pct
FROM (SELECT ... ) as one_day
JOIN (SELECT ... ) as three_day
ON one_day.activity_date = three_day.activity_date
JOIN (SELECT ... ) as seven_day
ON one_day.activity_date = seven_day.activity_date
您还可以使用IF()
子句以非连接方式执行此操作。如果在1天计数中,您可以创建一个列,否则为0,然后在聚合时计算总和。