您好!根据您提供的用户行为表,以下是用SQL计算产品漏斗数据的示例代码:
1. 计算每个步骤的用户留存量和留存率:
```sql
-- 点击下单按钮(click_order_button) 的用户留存量和留存率
SELEC
t COUNT(DISTINCT device_id) AS retention_count,
COUNT(DISTINCT device_id) / COUNT(DISTINCT device_id) OVER () AS retention_rate
FROM dwd_user_behavior
WHER
e action_id =
'click_order_button
';
-- 打开提交订单页 (open_submit_order_page) 的用户留存量和留存率
SELEC
t COUNT(DISTINCT device_id) AS retention_count,
COUNT(DISTINCT device_id) / COUNT(DISTINCT device_id) OVER () AS retention_rate
FROM dwd_user_behavior
WHER
e action_id =
'open_submit_order_page
';
-- 点击提交订单按钮(click_submit_order_button) 的用户留存量和留存率
SELEC
t COUNT(DISTINCT device_id) AS retention_count,
COUNT(DISTINCT device_id) / COUNT(DISTINCT device_id) OVER () AS retention_rate
FROM dwd_user_behavior
WHER
e action_id =
'click_submit_order_button
';
-- 打开支付页(open_payment_page) 的用户留存量和留存率
SELEC
t COUNT(DISTINCT device_id) AS retention_count,
COUNT(DISTINCT device_id) / COUNT(DISTINCT device_id) OVER () AS retention_rate
FROM dwd_user_behavior
WHER
e action_id =
'open_payment_page
';
-- 点击确认支付(click_/con
firm/i_payment) 的用户留存量和留存率
SELEC
t COUNT(DISTINCT device_id) AS retention_count,
COUNT(DISTINCT device_id) / COUNT(DISTINCT device_id) OVER () AS retention_rate
FROM dwd_user_behavior
WHER
e action_id =
'click_/con
firm/i_payment
';
-- 跳转支付成功页面(open_payment_success_page) 的用户留存量和留存率
SELEC
t COUNT(DISTINCT device_id) AS retention_count,
COUNT(DISTINCT device_id) / COUNT(DISTINCT device_id) OVER () AS retention_rate
FROM dwd_user_behavior
WHER
e action_id =
'open_payment_success_page
';
```
2. 计算每个步骤间的用户平均停留时间:
```sql
-- 点击下单按钮(click_order_button) 到打开提交订单页(open_submit_order_page) 的平均停留时间
SELEC
t AVG(DATEDIFF(action_time, LAG(action_time) OVER (ORDER BY action_time)) AS average_stay_time
FROM dwd_user_behavior
WHER
e action_id IN (
'click_order_button
',
'open_submit_order_page
');
-- 打开提交订单页(open_submit_order_page) 到点击提交订单按钮(click_submit_order_button) 的平均停留时间
SELEC
t AVG(DATEDIFF(action_time, LAG(action_time) OVER (ORDER BY action_time)) AS average_stay_time
FROM dwd_user_behavior
WHER
e action_id IN (
'open_submit_order_page
',
'click_submit_order_button
');
-- 点击提交订单按钮(click_submit_order_button) 到打开支付页(open_payment_page) 的平均停留时间
SELEC
t AVG(DATEDIFF(action_time, LAG(action_time) OVER (ORDER BY action_time)) AS average_stay_time
FROM dwd_user_behavior
WHER
e action_id IN (
'click_submit_order_button
',
'open_payment_page
');
-- 打开支付页(open_payment_page) 到点击确认支付(click_/con
firm/i_payment) 的平均停留时间
SELEC
t AVG(DATEDIFF(action_time, LAG(action_time) OVER (ORDER BY action_time)) AS average_stay_time
FROM dwd_user_behavior
WHER
e action_id IN (
'open_payment_page
',
'click_/con
firm/i_payment
');
-- 点击确认支付(click_/con
firm/i_payment) 到跳转支付成功页面(open_payment_success_page) 的平均停留时间
SELEC
t AVG(DATEDIFF(action_time, LAG(action_time) OVER (ORDER BY action_time)) AS average_stay_time
FROM dwd_user_behavior
WHER
e action_id IN (
'click_/con
firm/i_payment
',
'open_payment_success_page
');
```
本文地址:http://dfvalve.xrbh.cn/quote/7073.html
迅博思语资讯 http://dfvalve.xrbh.cn/ , 查看更多