首页 > 代码库 > sql-leetcode Consecutive Numbers

sql-leetcode Consecutive Numbers

 

技术分享

开始想 用 group 把Num都聚在一起

-- Group By语句从英文的字面意义上理解就是“根据(by)一定的规则进行分组(Group)”。
--它的作用是通过一定的规则将一个数据集划分成若干个小的区域,然后针对若干个小区域进行数据处理。但是group by是先排序后分组;

每个部门有多少人:

 

select DepartmentId as ‘部门名称‘, count(*) as ‘个数‘ from basicDepartment group by DepartmentId

  

所以不能使用group by ,将表复制3份进行比较:

select(Select DISTINCT l1.Num from Logs l1, Logs l2, Logs l3 where l1.Id=l2.Id-1 and l2.Id=l3.Id-1 and l1.Num=l2.Num and l2.Num=l3.Num) as ConsecutiveNums;

  

 

sql-leetcode Consecutive Numbers