数据库练习——leetcode(180):连续出现的数字
2020-03-24 19:16
573 查看
文章目录
连续出现的数字
题目
解析
首先一定要非常明确的是本题是要找连续出现的数字,连续!
如何判断连续,通过ID来判断,
步骤一:将表复制三份,分别命名为l1,l2,l3
select * from Logs as l1, Logs as l2, logs as l3
这个的效果为两个表相连接了,笛卡尔连接,一个ID对应另一个表的全部ID,效果如下:
步骤二:找到连续的学号:
select * from Logs as l1, Logs as l2, logs as l3where l1.id = l2.id-1 and l2.id = l3,id-1
效果如下
步骤三:找到出现三以上相等的数字
select * from Logs as l1, Logs as l2, logs as l3where l1.id = l2.id-1 and l2.id = l3.id-1 and l1.num = l2.num and l2.num =l3.num
步骤四:取出要找的结果
select distinct l1.Num as ConsecutiveNums from Logs as l1,Logs as l2,Logs as l3 where l1.id = l2.id-1 and l2.id = l3.id-1 and l1.Num = l2.Num and l2.Num = l3.Num
归纳:
select distinct l1.Num as ConsecutiveNums from Logs as l1,Logs as l2,Logs as l3 where l1.id = l2.id-1 and l2.id = l3.id-1 and l1.Num = l2.Num and l2.Num = l3.Num
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- LeetCode(180)-连续出现的数字
- 180. 连续出现的数字
- leetcode-腾讯精选练习(50 题)python #136 只出现一次的数字
- leetcode练习题-mysql:180. 连续出现的数字
- 数据库练习——leetcode(182):查找所有重复的电子邮箱(如何查找一个字段中重复的数字group by 与having)
- 180.连续出现的数字
- 查找练习 hash——出现过的数字
- leetcode136 只出现一次的数字
- sdut2123查找练习 hash——出现过的数字
- leetcode:137. 只出现一次的数字 II
- LeetCode[967]连续差相同的数字
- 查找练习 hash——出现过的数字
- leetcode解题之136 #Single Number Java版(只出现一次的数字)
- SDUTACM 查找练习 hash——出现过的数字
- python [LeetCode] 只出现一次的数字
- 只出现一次的数字 [ LeetCode ]
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字 分类: 查找 2015-06-18 17:30 7人阅读 评论(0) 收藏
- 查找练习hash-出现过的数字
- 查找练习 hash——出现过的数字