简体   繁体   English

MYSQL 计算转化率

[英]MYSQL Calculate Conversion Rate

I could manage to return the correct Conversion Rate with this query:我可以设法用这个查询返回正确的转换率:

SELECT date(ordertime), (count(*) / ( SELECT sum(uniquevisits) FROM s_statistics_visitors WHERE datum = '2020-11-25') * 100) AS 'CONVERSION RATE' FROM s_order WHERE date(ordertime) = '2020-11-25' AND subshopID = 1 GROUP BY date(ordertime); Z63225F19FCCB18E7C709F1F1FA11BC738EZ日期(订购时间),(count(Z63225F19F19F19FCCB18E7C709F1FA1FA1FA1FA1BC738EZ sum sum s _Statistics_visitsions_visitys_visitirire wity with with werime) 11-25' AND subshopID = 1 GROUP BY date(ordertime);

But it only returns the CR for one specific date.但它只返回一个特定日期的 CR。 It wont work with the between keyword.它不适用于 between 关键字。 The subquery returns more then one result, if I delete the where condition in the subquery.如果我删除子查询中的 where 条件,子查询会返回一个以上的结果。

Schema for s_statistics: id, shopID, datum, uniquevisits, devicetype Schema for s_order: id, ordernumber, ordertime, shopID s_statistics 的架构:id、shopID、datum、uniquevisits、devicetype s_order 的架构:id、ordernumber、ordertime、shopID

Since s_statistics saves values for each devicetype I have to sum uniquevisits per day.由于 s_statistics 保存了每种设备类型的值,因此我必须对每天的 uniquevisits 求和。 But the group by date(ordertime) at the end of my query does not affect the subquery.但是我的查询末尾的按日期(订单时间)分组不会影响子查询。

-original post- I want to calculate the conversion rate for an onlineshop. -原始帖子-我想计算在线商店的转化率。

The data is held in two tables.数据保存在两个表中。

Schema1 statistics: id / shopID / datum(yyyy-mm-dd) / uniquevisits / devicetype Schema1 统计信息: id / shopID / datum(yyyy-mm-dd) / uniquevisits / devicetype

Schema2 order: id / ordernumber / ordertime (YYYY-MM-DD HH-MM-SS) Schema2 订单: id / ordernumber / ordertime (YYYY-MM-DD HH-MM-SS)

Upon my knowledge the conversionrate calculates like:据我所知,转换率计算如下:

(unique visits per day / 1000) * orders per day

I tried something like this:我试过这样的事情:

SELECT
((count(ordernumber) / 1000) * (select sum(s_statistics_visitors.uniquevisits) 
FROM s_statistics_visitors GROUP BY* datum))

FROM s_order where subshopID= '1' 
GROUP BY date_format(ordertime, '%d%m%y') 
ORDER BY date_format(ordertime, '%d%m%y')

I know that my query wont work - since there is no join - but I believe it might be the right approach.我知道我的查询不起作用——因为没有加入——但我相信这可能是正确的方法。 I could you join on the the date.我可以你参加的日期。

The problem: the dateformat in the table: s_statistics_visitors is YYYY-MM-DD问题:表中的日期格式: s_statistics_visitors is YYYY-MM-DD

and in order: YYYY-MM-DD HH-MM-SS并按顺序: YYYY-MM-DD HH-MM-SS

You seem to want something like this:你似乎想要这样的东西:

SELECT sv.datum, sv.shopId, count(*) as num_orders,
       (count(*) / 1000) / sv.uniquevisits)
FROM s_order o JOIN
     s_statistics_visitors sv
     ON sv.datum = DATE(o.ordertime) AND
        sv.shopId = o.shopId
GROUP BY sv.datum, sv.shopId, sv.uniqevisits ;

Note: This assumes that shopId is in both tables -- which makes sense for how you have described the problem.注意:这假设shopId在两个表中 - 这对于您描述问题的方式是有意义的。 If not, you can adjust the shop id logic.如果没有,您可以调整商店 id 逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM