大数据第33天—MySQL练习题4-杨大伟
展示效果:
ConsecutiveNums |
---|
1 |
1 Create table If Not Exists Logs (Id int, Num int); 2 3 insert into Logs (Id, Num) values (1, 1); 4 insert into Logs (Id, Num) values (2, 1); 5 insert into Logs (Id, Num) values (3, 1); 6 insert into Logs (Id, Num) values (4, 2); 7 insert into Logs (Id, Num) values (5, 1); 8 insert into Logs (Id, Num) values (6, 2); 9 insert into Logs (Id, Num) values (7, 2);
最终SQL:
1 SELECT * 2 FROM 3 Logs l1, 4 Logs l2, 5 Logs l3 6 WHERE 7 l1.Id = l2.Id - 1 AND l1.Num = l2.Num 8 AND l2.Id = l3.Id - 1 AND l2.Num = l3.Num;