标签:链接 连接 表连接 pre count sel 编写 HERE join
select distinct Num ConsecutiveNums from (select a.Num Num, count(b.Num) 总数 from Logs a join Logs b on b.Id - a.Id <=2 and a.Num = b.Num and b.Id - a.Id >= 0 group by a.Id )t where t.总数 >= 3
首先进行了双表连接,双表连接的条件是:id值的相差范围是0到2,而且Num相同;
然后从join表中选择出Num和Num出现的次数;
最后外层查询再从中选择出次数大于等于3的Num;
标签:链接 连接 表连接 pre count sel 编写 HERE join
原文地址:https://www.cnblogs.com/chxyshaodiao/p/12461407.html