当前位置:网站首页>SQL continuous login problem
SQL continuous login problem
2022-06-30 19:29:00 【Game programming】
sql Continuous login problem
Today we have a video , Requirements are calculated in a library table , Inquire about 2022 year 1 Users who log in for three consecutive days in the month and the duration of continuous login .
First ,t_login It records the time information of each login .
Log in multiple times a day , Just record one ;
( Using functions invalidates the index )
select distinct uid,date(login_time) ymdfrom t_loginwhere login_time between '2022-01-01 00:00:00' and timestamp '2022-01-31 23:59:59';Rough way , Self associate the above table three times , shortcoming , Expandability of .
select t1.uid,t1.ymd,t2.ymd,t3.ymd from(select distinct uid,date(login_time) ymdfrom t_loginwhere login_time between '2022-01-01 00:00:00' and timestamp '2022-01-31 23:59:59') t1join(select distinct uid,date(login_time) ymdfrom t_loginwhere login_time between '2022-01-01 00:00:00' and timestamp '2022-01-31 23:59:59') t2on(t1.uid=t2.uid and datediff(t2.ymd,t1.tmd)=1)join(select distinct uid,date(login_time) ymdfrom t_loginwhere login_time between '2022-01-01 00:00:00' and timestamp '2022-01-31 23:59:59') t3on(t2.uid=t3.uid and datediff(t3.ymd,t2.tmd)=1);Mode two
Use window functions , Partition restrictions , obtain
with t1 as (select distinct uid,date(login_time) ymd from t_login where login_time between timestamp '2022-01-01 00:00:00' and timestamp '2022-01-31 23:59:59') select uid,ymd,row_number() over (partition by uid order by ymd) numfrom t1; 
As long as it's not continuous , There must be a result jump in interpolation .
with t1 as (select distinct uid,date(login_time) ymd from t_login where login_time between timestamp '2022-01-01 00:00:00' and timestamp '2022-01-31 23:59:59') t2 as(select uid,ymd,date_sub(ymd,interval row_number() over (partition by uid order by ymd) day) sub_datefrom t1)select uid,min(ymd),max(ymd),count(*)from t2group by uid,sub_datehaving count(*)>=3; Fucking regret , It's a waste of time . Alas, I have no time to sigh .
author : Why not sell egg cakes well
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .
边栏推荐
- JS string interception method summary
- 小球大小随机,随机运动碰撞
- 全技术栈、全场景、全角色云原生系列培训重磅首发,助力企业打造硬核云原生技术团队
- CTF流量分析常见题型(二)-USB流量
- Development: how to install offline MySQL in Linux system?
- 设计电商秒杀系统
- 法国A+ 法国VOC标签最高环保级别
- How to improve the three passive situations in data analysis
- Electron 入门
- 项目配置了eslint,编辑器没有关闭eslint功能的情况下,eslint没有生效
猜你喜欢

Four tips tell you how to use SMS to promote business sales?

Opencv data type code table dtype

如何使用物联网低代码平台进行服务管理?

How to seamlessly transition from traditional microservice framework to service grid ASM

Entropy - conditional entropy - joint entropy - mutual information - cross entropy

年复一年,为什么打破数据孤岛还是企业发展的首要任务
![[JetsonNano] [教程] [入门系列] [一] 如何开启VNC共享](/img/f5/3f0f69739caa22809f40cf4b7483fe.png)
[JetsonNano] [教程] [入门系列] [一] 如何开启VNC共享

sqlserver SQL Server Management Studio和Transact-SQL创建账户、创建访问指定数据库的只读用户

Task01:初识数据库与SQL(笔记1)

Video content production and consumption innovation
随机推荐
反射创建实例三种方式(2022.6.6-6.12)
JVM常见问题
20220528【聊聊假芯片】贪便宜往往吃大亏,盘点下那些假的内存卡和固态硬盘
DTD modeling
项目配置了eslint,编辑器没有关闭eslint功能的情况下,eslint没有生效
20220528 [talk about fake chips] those who are greedy for cheap often suffer heavy losses. Take stock of those fake memory cards and solid state drives
嵌入式软件开发新趋势:DevOps
How JS correctly clears all child elements under an element
企业选型作业上常犯的一个错误
Gateway服务网关
基于 actix、async-graphql、rbatis、pgsql/mysql 构建 GraphQL 服务(4)-变更服务
在广州的朋友,有机会可以参加下
【DesignMode】单例模式(singleton pattern)
Swin-transformer --relative positional Bias
How to open a futures account safely? Which futures companies are more reliable now?
Opencv data type code table dtype
How to seamlessly transition from traditional microservice framework to service grid ASM
Ditto设置全局仅粘贴文本快捷键
Kubernetes----Pod配置容器启动命令
Temperature measuring instrument based on STM32 single chip microcomputer