当前位置:Gxlcms > 数据库问题 > sql-leetcode Consecutive Numbers

sql-leetcode Consecutive Numbers

时间:2021-07-01 10:21:17 帮助过:29人阅读

 

技术分享

开始想 用 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

标签:意义   from   ons   tin   数据   个数   名称   排序   distinct   

人气教程排行