当前位置:网站首页>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
边栏推荐
- 开源一款监控数据采集器,啥都能监控
- Handling method of Oracle data file header SCN inconsistency
- Endgame P.O.O
- 达梦数据库如何定位锁等待问题解决方法
- 正则匹配手机号
- NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
- Use of vim
- P6117-[joi 2019 final] greedy
- ORA-16038 ORA-19502 ORA-00312故障处理
- Oracle数据库监听文件配置
猜你喜欢

NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!

5 minutes, excellent customer service chat handling skills

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

SSH Remote Password free login

数字化转型的失败原因及成功之道

R ellipse random point generation and drawing

ThinkPHP5多语言切换项目实战

如何提高网络基础设施排障效率,告别数据断档?

文献调研报告
![[GDB debugging tool] | how to debug under multithreading, multiprocessing and running programs](/img/b5/38a53c88240c4308452d0208173461.png)
[GDB debugging tool] | how to debug under multithreading, multiprocessing and running programs
随机推荐
Grpc local test joint debugging tool bloomrpc
LeetCode: 137. 只出现一次的数字 II
什么情况下应该使用GridFS?
【Eureka 源码分析】
Symbol.iterator 迭代器
How do novices choose the grade of investment and financial products?
Servlet fast foundation building
indexedDB本地存储,首页优化
How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
生产者/消费者模型
How to solve multi-channel customer communication problems in independent stations? This cross-border e-commerce plug-in must be known!
Practical analysis: implementation principle of APP scanning code landing (app+ detailed logic on the web side) with source code
Ora-28000 error after upgrading Oracle 12C to 19C
In depth analysis of Apache bookkeeper series: Part 3 - reading principle
正则匹配手机号
十大证券公司哪个佣金最低,最安全可靠?有知道的吗
Dragging El table sortablejs
记录一下MySql update会锁定哪些范围的数据
带文字的seekbar : 自定义progressDrawable/thumb :解决显示不全
针对《VPP实现策略路由》的修正