当前位置:网站首页>SQL practice: SQL solves problems for X consecutive days
SQL practice: SQL solves problems for X consecutive days
2022-06-10 06:07:00 【Soyoger】
In the last section , Through the case of user retention , Explain the solution X The idea of the question of heaven , Next , In this section, let's take a look at continuity X God's question , This kind of problem is often needed to be solved in the interview and actual business .
First, the continuous indicators 、 Make a definition , as follows :
- 1 Day after day : After login on the same day , I logged in the next day , such as 2021.2.10 Logged in ,2021.2.11 Logged in is counted as 1 Day after day .
- 3 Day after day : After login on the same day , On the second and third days, I also logged in , such as 2021.2.10 Logged in ,2021.2.11 and 2021.2.12 Logged in is counted as 3 Day after day .
- And so on ···
Now suppose , There is a user login form t_user_login, Field user_id and login_time Represent users respectively id And landing time . Next , We go through SQL To find continuity 3 Japan 、7 Users who log in on the th .
commonly , Solve such continuous problems X The idea of the heaven problem is as follows :
- First step , You can use window functions to user_id Grouping sorting rn;
- The second step , Subtract the sequence number after sorting from the login time rn;
- The third step , If the dates are consecutive , The date will be the same .
below , We use a case to illustrate .
First , Let's build t_user_login surface .
DROP TABLE IF EXISTS `边栏推荐
- Practice of Flink CDC + Hudi massive data entering the lake in SF
- PM2 installation and common commands
- WireShark抓包分析
- 基于模型的多智能体强化学习中的模型学习理解
- 如何通过netstat命令分析网络情况
- Focus on web development, simple web development
- 异构网络是什么?
- QT上位机 通过EGM实时控制ABB
- What does IP address 0.0.0.0 mean?
- Working with MySQL databases in a project
猜你喜欢

5. inverse Polish representation, ternary expression, quaternion expression

Machine learning notes - what are Bleu scores?

Xshell download, install and use simple tutorial

Wireshark packet capture analysis

Time complexity and space complexity

ArcGIS应用(十九)Arcgis 统计分析计算多波段图像最大值、最小值、平均值等

String cutting group by
Solution to permission denied in pushing code to coding

idea 远程调试代码

MKS h3615ns DC motor drive instruction manual
随机推荐
Paper reading (54):deepfool: a simple and accurate method to four deep neural networks
sql基础
Timewindowall of Flink
What is the 8b/10b code?
APM flight control learning notes hovering loiter mode -cxm
Basic concepts of multithreading family
如何通过netstat命令分析网络情况
Builder pattern
excel中如何把文本转换成数值?
Idea remote debugging code
ArcGIS应用(十九)Arcgis 统计分析计算多波段图像最大值、最小值、平均值等
String cutting group by
Crash problem
pm2 的安装与常用命令
Generation of different random numbers in MATLAB
What is ARP (address resolution protocol)?
Multithreaded producer and consumer model
Method of canceling automatic numbering
取消自动编号的方法
C # student management system designed to cope with most examination sites involved in the final period