LeetCode.180. 连续出现的数字
分析:
自连接两次,每次差值为1,检索第一个表即可。
代码:
select distinct l1.Num as ConsecutiveNums
from Logs l1 left join Logs l2 on l1.Id=l2.Id-1 left join Logs l3 on l2.Id=l3.Id-1
where l1.Num=L2.Num and l2.Num=l3.Num;
分析:
自连接两次,每次差值为1,检索第一个表即可。
代码:
select distinct l1.Num as ConsecutiveNums
from Logs l1 left join Logs l2 on l1.Id=l2.Id-1 left join Logs l3 on l2.Id=l3.Id-1
where l1.Num=L2.Num and l2.Num=l3.Num;