1. Create a test table CREATE TABLE `testsign` ( `userid` int(5) DEFAULT NULL, `username` varchar(20) DEFAULT NULL, `signtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `type` int(1) DEFAULT '0' COMMENT '0 represents sign-in data, 1 represents sign-in date dictionary data' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 2. Insert test data. The sign-in time is from May 21 to June 5. It can be written live, but it is necessary to write a stored procedure. I am lazy. The focus should be on the code for getting the sign-in data, which is the third point. Haha insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-21 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-22 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-23 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-24 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-25 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-26 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-27 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-28 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-29 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-30 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-05-31 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-06-01 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-06-02 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-06-03 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-06-04 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('72164','Dictionary','2017-06-05 00:00:00','1'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('800675','Wu Xiaoshuang sign-in data','2017-05-21 00:00:00','0'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('800675','Wu Xiaoshuang sign-in data','2017-05-22 00:00:00','0'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('800675','Wu Xiaoshuang sign-in data','2017-05-23 00:00:00','0'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('800675','Wu Xiaoshuang sign-in data','2017-05-24 00:00:00','0'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('800675','Wu Xiaoshuang sign-in data','2017-05-25 00:00:00','0'); insert into `testsign` (`userid`, `username`, `signtime`, `type`) values('800675','Wu Xiaoshuang sign-in data','2017-05-26 00:00:00','0'); 3. Query continuous sign-in data SELECT * FROM testsign WHERE TYPE=0 AND DATE_FORMAT(signtime,'%Y%m%d')>( SELECT IFNULL(MAX(DATE_FORMAT(signtime,'%Y%m%d')),"20170520") FROM testsign WHERE TYPE=1 AND DATE_FORMAT(signtime,'%Y%m%d')<=DATE_ADD(NOW(), INTERVAL -1 DAY) AND DATE_FORMAT(signtime,'%Y%m%d') NOT IN ( SELECT DATE_FORMAT(signtime,'%Y%m%d') FROM testsign WHERE TYPE=0 AND userid=800675 ) ) AND DATE_FORMAT(signtime,'%Y%m%d')<='20170605' AND userid=800675 Uninterrupted data Delete the data on the 23rd, and start counting from the 24th, and sign for three consecutive days The above is the MYSQL implementation of the continuous sign-in function introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: A brief analysis of how to upgrade PHP 5.4 to 5.6 in CentOS 7
>>: Detailed explanation of using scp command to copy files remotely in Linux
Operating system: Ubuntu 17.04 64-bit MySQL versi...
Table of contents 1. Introduction 2. Simple epoll...
Vue data two-way binding principle, but this meth...
introduce HTML provides the contextual structure ...
Table of contents Creating HTML Pages Implement t...
Preface Students who learn JavaScript know that A...
Table of contents 1. About JavaScript 2. JavaScri...
Introduction to Debian Debian in a broad sense re...
Borrowing Constructors The basic idea of this t...
This article example shares the specific code of ...
When learning kubernetes, we need to practice in ...
Table of contents Listener 1.watchEffect 2.watch ...
The VMware Workstation Pro version I use is: 1. F...
Table of contents 1:mysql execution process 1.1: ...
I’ve always preferred grayscale images because I t...