Create a tablecreate table order(id varchar(10),date datetime,orders varchar(10)); insert into orde values('1' , '2019/1/1',10 ) insert into orde values('1' , '2019/1/2',109 ) insert into orde values('1' , '2019/1/3',150 ) insert into orde values('1' , '2019/1/4',99) insert into orde values('1' , '2019/1/5',145) insert into orde values('1' , '2019/1/6',1455) insert into orde values('1' , '2019/1/7',199) insert into orde values('1' , '2019/1/8',188 ) insert into orde values('4' , '2019/1/1',10 ) insert into orde values('2' , '2019/1/2',109 ) insert into orde values('3' , '2019/1/3',150 ) insert into orde values('4' , '2019/1/4',99) insert into orde values('5' , '2019/1/5',145) insert into orde values('6' , '2019/1/6',1455) insert into orde values('7' , '2019/1/7',199) insert into orde values('8' , '2019/1/8',188 ) insert into orde values('9' , '2019/1/1',10 ) insert into orde values('9' , '2019/1/2',109 ) insert into orde values('9' , '2019/1/3',150 ) insert into orde values('9' , '2019/1/4',99) insert into orde values('9' , '2019/1/6',145) insert into orde values('9' , '2019/1/9',1455) insert into orde values('9' , '2019/1/10',199) insert into orde values('9' , '2019/1/13',188 ) IdeasGroup the table by id and rank by time, subtract the rank rnk from the time. If the time is continuous, the subtraction result is equal: select *,date-rankrnk from (select *,row_number() over(partition by id order by date) rankfrom orde) a; Then group by id, rnk, and count select id,rnk,count(*) ok from (select *,date-rankrnk from (select *,row_number() over(partition by id order by date) rankfrom orde) a) b group by id,rnk; The following table is obtained: Finally, filter the count items ok>=7. You can also filter directly: select id,rnk from (select *,date-rankrnk from (select *,row_number() over(partition by id order by date) rankfrom orde) a) b group by id,rnk having count(*)>=7; The above is the SQL query that the editor introduced to you for users who have placed orders for at least seven consecutive days. I hope it will be helpful to you. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: 5 basic skills of topic page design (Alibaba UED Shanmu)
>>: What are the new CSS :where and :is pseudo-class functions?
Table of contents MySQL multiple instances Multi-...
Table of contents 1. Location / Matching 2. Locat...
Table of contents I. Overview 2. pt-archiver main...
This article uses examples to describe MySQL tran...
At the beginning of the new year, I would like to...
Table of contents What is the Linux system that w...
Table of contents 1. Use SVG 2. Use fontAwesome 3...
Preface Today I installed MySQL and found that th...
1. Create a folder to store nginx shell scripts /...
Table of contents 1. Use help information 2. Crea...
Is it the effect below? If so, please continue re...
This article example shares the specific code of ...
The author recently encountered a performance bot...
illustrate MySql Community Edition supports table...
Recently, I needed to test the zoom video confere...