当前位置:网站首页>MySQL面试真题(二十)——视频数据分析实战
MySQL面试真题(二十)——视频数据分析实战
2022-06-22 07:04:00 【Socialphobia_FOGO】
"用户操作记录表"里记录着每天某短视频平台的用户点击访问情况,以便帮助公司内部分析师了解用户对于当前页面的点击偏好。
表包字段有:用户名、操作记录、操作时间。

其中表内各字段含义如下:
用户名——表示用户在该短视频平台注册的唯一用户名。
操作记录——表示用户在该短视频平台点击的按钮名称。A表示用户点击“短视频”播放入口,B表示用户点击“长视频”播放入口。
操作时间——表示用户点击时候的时间,精确到秒。
现在运营人员找到作为数据分析师的你,想让你帮忙看看用SQL取两个数据,具体如下:
1.分析每天的访客数和他们的平均操作次数;
结果如下:
2.统计每天符合以下条件的用户数:A操作之后是B操作,AB操作必须相邻;
结果如下:
#1.分析每天的访客数和人均操作次数
SELECT
DATE(操作时间) AS 日期,
COUNT(DISTINCT 用户名) AS 每天访客数,
COUNT(操作记录) / COUNT(DISTINCT 用户名) AS 人均操作次数
FROM
用户操作记录表
GROUP BY DATE(操作时间)
#2.统计每天符合以下条件的用户数:A操作之后是B操作,AB操作必须相邻。
SELECT
DATE(操作时间) AS 日期,
COUNT(
DISTINCT
CASE
WHEN 操作记录 = 'A'
AND 下次操作记录 = 'B'
THEN 用户名
ELSE NULL
END
) AS 用户数
FROM
(SELECT
*,
lead (操作记录) over (
PARTITION BY 用户名,
DATE(操作时间)
ORDER BY 操作时间
) AS 下次操作记录
FROM
用户操作记录表) a
GROUP BY DATE(操作时间)
边栏推荐
- Network layer: IP protocol
- Error: unable to find vcvarsall Solutions to bat errors
- Vue failed to connect to MySQL database
- [rust daily] January 23, 2022 webapi benchmarking
- [fundamentals of machine learning 03] gbdt (gradient boost decision tree)
- Wildfire stm32f407zgt6 learning notes beginner level chapter basic knowledge points
- buuctf部分题目wp
- 2022年毕业生求职找工作青睐哪个行业?
- Introduction to 51 single chip microcomputer - LED light
- 猿辅导最强暑假计划分享:暑假计划这样做,学习玩耍两不误
猜你喜欢

【GAN】《ENERGY-BASED GENERATIVE ADVERSARIAL NETWORKS》 ICLR‘17

Xh_CMS渗透测试文档

The mountains and rivers are heavy, and there is no doubt that there is no way out. There is another village where the willows are dark and the flowers are bright.

如何才能有效缓解焦虑?看看猿辅导怎么说

Introduction to 51 Single Chip Microcomputer -- minimum system of single chip microcomputer

OpenGL - Textures

Qt development simple Bluetooth debugging assistant (low power Bluetooth)

汇编学习《汇编语言(第三版)》王爽著第四章学习
![[fundamentals of machine learning 02] decision tree and random forest](/img/24/28964279ea479476e1a232aec9c599.jpg)
[fundamentals of machine learning 02] decision tree and random forest

Neuron+eKuiper 实现工业物联网数据采集、清理与反控
随机推荐
Dijin introduces digi connectcore voice control software for connectcore system module
OpenGL - Textures
Event preview edgex developer summit @ Nanjing station is coming!
[out of distribution detection] deep analog detection with outlier exposure ICLR '19
迪进面向ConnectCore系统模块推出Digi ConnectCore语音控制软件
How to learn 32-bit MCU
Up sampling and down sampling (notes, for personal use)
6. install the SSH connection tool (used to connect the server of our lab)
33岁程序员的年中总结
Network layer: IP protocol
CNN模型合集 | Resnet变种-WideResnet解读
猿辅导最强暑假计划分享:暑假计划这样做,学习玩耍两不误
The journey of an operator in the framework of deep learning
[fundamentals of machine learning 03] gbdt (gradient boost decision tree)
自然语言处理理论和应用
Map of STL knowledge summary
In 2022, which industry will graduates prefer when looking for jobs?
Self supervised learning for general out of distribution detection AAAI '20
【GCN-RS】UltraGCN: Ultra Simplification of Graph Convolutional Networks for Recommendation (CIKM‘21)
C语言——深入理解数组