开始想 用 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的更多相关文章

  1. [LeetCode] Consecutive Numbers 连续的数字 --数据库知识(mysql)

    1. 题目名称   Consecutive Numbers 2 .题目地址 https://leetcode.com/problems/consecutive-numbers/ 3. 题目内容 写一个 ...

  2. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  3. LeetCode——Consecutive Numbers

    Description: Write a SQL query to find all numbers that appear at least three times consecutively. + ...

  4. leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)

    一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...

  5. LeetCode Database: Consecutive Numbers

    Consecutive Numbers Write a SQL query to find all numbers that appear at least three times consecuti ...

  6. 【leetcode】1296. Divide Array in Sets of K Consecutive Numbers

    题目如下: Given an array of integers nums and a positive integer k, find whether it's possible to divide ...

  7. [SQL]LeetCode180. 连续出现的数字 | Consecutive Numbers

    SQL架构: Create table If Not Exists Logs (Id int, Num int) Truncate table Logs insert into Logs (Id, N ...

  8. 【SQL】180. Consecutive Numbers

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. [LeetCode#180]Consecutive Numbers

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  10. [LeetCode] 829. Consecutive Numbers Sum 连续数字之和

    Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers? ...

随机推荐

  1. poj2524(并查集水题)

    题目链接:http://poj.org/problem?id=2524 题目大意:学校共有n个同学,告诉你m对同学信仰同一宗教,问这个学校学生信仰宗教的数目最多为多少. 例: Sample Input ...

  2. jquery 追加元素/jquery文档处理,插入、修改、移动、删除指定的DOM元素.

    jquery 追加元素 $("#content").append("..."); // 添加到元素内部最后面 $("#content").p ...

  3. sublime安装说明

    安装Install package https://www.cnblogs.com/lixuwu/p/5693624.html 常用配置 Perference → Settings – User,用下 ...

  4. 原生JS正则实现trim()

    Jquery中封装有trim() 原生需要自己实现,我们可以用原型的方式自己封装trim()方法,实现去掉前后空格.前空格.后空格...所以不必抱怨,简单又灵活,这才是强大的JS的特色 String. ...

  5. Codeforce 867 C. Ordering Pizza (思维题)

    C. Ordering Pizza It's another Start[c]up finals, and that means there is pizza to order for the ons ...

  6. (编辑距离问题 线性DP) nyoj1431-DNA基因鉴定

    题目描述: 我们经常会听说DNA亲子鉴定是怎么回事呢?人类的DNA由4个基本字母{A,C,G,T}构成,包含了多达30亿个字符.如果两个人的DNA序列相差0.1%,仍然意味着有300万个位置不同,所以 ...

  7. 二叉树建立及遍历 C++ 源码

    #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include <stdlib.h> using namespace s ...

  8. Spring Boot笔记四:日志框架介绍

    我是一名程序员,我喜欢写System.out.println来打印一些重要的信息...后来我学了面向对象,我把这些输出语句整合到了一个工具类里面,可以打印,也可以保存日志. 我是一名积极思考的程序员, ...

  9. HDFS-Shell 文件操作

    一.操作 HDFS 上的文件有两个命令可以用 hdfs dfs:只能操作 HDFS 上的文件 Usage: hdfs [--config confdir] [--loglevel loglevel] ...

  10. Systemd 添加自定义服务(开机自启动)

    Systemd 简介:https://fedoraproject.org/wiki/Systemd/zh-cn 一.service unit 常用命令,以 mysql 服务为例 # 开机启动 syst ...