当前位置:网站首页>SQL statistics of users logged in for N consecutive days
SQL statistics of users logged in for N consecutive days
2022-06-24 09:51:00 【The figure under the stars】
Their thinking
- user Number of logins per day Probably not only once , Therefore, first set the user's login date every day duplicate removal ;
- Then press user ID grouping , according to Login date (yyyy-mm-dd) Sort rn;
- Calculation Login date -rn( Sort value of step 2 ) as diff_date – When the user logs in continuously , The result of each subtraction is the same ;
- according to user_id, diff_date grouping , Statistics count(*)>N The number of , That is, the final result .
Code implementation
select
user_id, login_date, diff_date
from(
select
user_id, login_date,
date_sub(login_date, rn) diff_date -- The third step
from(
select
user_id, login_date,
row_number() over(partition by user_id order by login_date) rn -- The second step
from(select distinct user_id, login_date from login_info)t -- First step
)tt
)ttt
group by user_id, diff_date
having count(*)>N
边栏推荐
- Tnsnames Ora file configuration
- 二叉樹第一部分
- Implementation of simple floating frame in WindowManager
- NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
- 蜜罐2款hfish,ehoney
- R ellipse random point generation and drawing
- 如何规范化数据中心基础设施管理流程
- 数字化转型的失败原因及成功之道
- Use of vim
- Thinkphp5 clear the cache cache, temp cache and log cache under runtime
猜你喜欢

居家办公如何管理数据中心网络基础设施?

ByteDance Interviewer: talk about the principle of audio and video synchronization. Can audio and video be absolutely synchronized?

PRCT-1400 : 未能执行 getcrshome解决方法

CICFlowMeter源码分析以及为满足需求而进行的修改

Jcim | AI based protein structure prediction in drug discovery: impacts and challenges

Record the range of data that MySQL update will lock

Binary tree part I

如何规范化数据中心基础设施管理流程

Summary of medical image open source datasets (II)

操作符详解
随机推荐
In depth study paper reading target detection (VII) Chinese English Bilingual Edition: yolov4 optimal speed and accuracy of object detection
LeetCode: 240. 搜索二维矩阵 II
Operator details
Tnsnames Ora file configuration
什么情况下应该使用GridFS?
LeetCode: 240. Search 2D matrix II
PHP使用递归和非递归方式实现创建多级文件夹
Threejs MMD model loading + contour loading + animation loading + Audio loading + camera animation loading +ammojs loading gltf model loading +gltf reflection adjustment
Record the range of data that MySQL update will lock
居家办公如何管理数据中心网络基础设施?
针对《VPP实现策略路由》的修正
Grpc local test joint debugging tool bloomrpc
Oracle的tnsnames.ora文件配置
[Eureka source code analysis]
使用Live Chat促進業務銷售的驚人技巧
Symbol.iterator 迭代器
数组无缝滚动demo
五心红娘
threejs的点光源+环境光
PTA monkey chooses King (Joseph Ring problem)