-- uv、pv、留存率(按⽇)统计
-- pv 按日分组,统计 count behavior_type = 1
-- uv 按日统计,统计 count distinct user_id
-- pv/uv
SELECT
dates,
COUNT(IF(behavior_type = 1,user_id,null)) AS 'pv',
COUNT( DISTINCT user_id ) AS 'uv',
COUNT(IF(behavior_type = 1,user_id,null))/COUNT( DISTINCT user_id ) AS 'pv/uv'
FROM
tmp_table
GROUP BY
dates;
DROP view user_remain;
-- 活跃用户留存率
CREATE VIEW user_remain AS SELECT
a.dates,
COUNT( DISTINCT a.user_id ) AS 'user_count',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 1,
b.user_id,
NULL
)) AS 'remain1',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 2,
b.user_id,
NULL
)) AS 'remain2',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 3,
b.user_id,
NULL
)) AS 'remain3',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 4,
b.user_id,
NULL
)) AS 'remain4',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 5,
b.user_id,
NULL
)) AS 'remain5',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 6,
b.user_id,
NULL
)) AS 'remain6',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 7,
b.user_id,
NULL
)) AS 'remain7',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 15,
b.user_id,
NULL
)) AS 'remain15',
COUNT(
DISTINCT
IF
(
DATEDIFF( b.dates, a.dates )= 30,
b.user_id,
NULL
)) AS 'remain30'
FROM
(
SELECT
user_id,
dates
FROM
tmp_table
GROUP BY
user_id,
dates
) a
LEFT JOIN (
SELECT
user_id,
dates
FROM
tmp_table
GROUP BY
user_id,
dates
) b ON a.user_id = b.user_id
WHERE
b.dates > a.dates
GROUP BY
a.dates;
SELECT
dates,
user_count,
CONCAT(cast((remain1/user_count*100) as DECIMAL(10,2)),'%') as 'day1',
CONCAT(cast((remain2/user_count*100) as DECIMAL(10,2)),'%') as 'day2',
CONCAT(cast((remain3/user_count*100) as DECIMAL(10,2)),'%') as 'day3',
CONCAT(cast((remain4/user_count*100) as DECIMAL(10,2)),'%') as 'day4',
CONCAT(cast((remain5/user_count*100) as DECIMAL(10,2)),'%') as 'day5',
CONCAT(cast((remain6/user_count*100) as DECIMAL(10,2)),'%') as 'day6',
CONCAT(cast((remain7/user_count*100) as DECIMAL(10,2)),'%') as 'day7',
CONCAT(cast((remain15/user_count*100) as DECIMAL(10,2)),'%') as 'day15',
CONCAT(cast((remain30/user_count*100) as DECIMAL(10,2)),'%') as 'day30'
FROM
user_remain;
uv、pv、浏览深度、留存率
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 关于老北京的书籍和文章着实不在少数,许多文人、学者、名家们都用文字怀念或记录过老北京,而瞿宣颖所著的《北京味儿》还...
- 一、我眼中的用户留存 之前写过一篇《从“驾校一点通”的体验,谈工具类产品的运营模式》的文章,发表在人人都是产品经理...
- 一、分析目的 2020年新冠疫情爆发,国人开启了一段漫长的居家生活时期,线下娱乐转移到了线上,短视频行业用户渗透率...