开始想 用 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. Cookie知识点总结

    Cookie机制是采用客户端保持Http状态信息的方案. Cookie是在浏览器访问web服务器的某个资源的时候,由web服务器在http响应消息头中附带给浏览器的一个小文本文件. 一旦web服务器保 ...

  2. 数组和list互转

    数组转list 方法1: String[] stringArray = { "a", "b", "c", "d", &q ...

  3. 加密解密DES之Android、IOS、C#实现

    Android实现 package com.sto.express.utils; import java.security.MessageDigest; import java.security.sp ...

  4. Java programming problems

    1.使用循环把26个字母按字典顺序存入数组,在不使用另外数组的情况下将其逆序存放,在根据处理后的字符数组创建一个字符串并输出 public static void main(String[] args ...

  5. C# Winfom 中ListBox的简单用法

    https://www.cnblogs.com/xielong/p/6744805.html Winform控件ListBox的用法 1.如何添加listBox的值 this.listBox1.Ite ...

  6. Day4--Python--列表增删改查,元组,range

    # 一.列表# 能装东西的东西 列表中装的数据是没有限制的,大小基本上够用# 列表用[]表示# 有索引和切片 [start,end,step] ###增删改查 (重点) # 1.新增 # appent ...

  7. http uri唯一标识

    URI:唯一标识并且信息资源(简单理解为:发邮件的地址,身份证号).uri包括url 比如通过查找一个uri,找到一张图片“https://timgsa.baidu.com/timg?image&am ...

  8. (BFS 二叉树) leetcode 515. Find Largest Value in Each Tree Row

    You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 ...

  9. (数学) PTA 1005 继续(3n+1)猜想 (25 分)

    1005 继续(3n+1)猜想 (25 分) 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程 ...

  10. 【转载】 qml: MouseArea重叠问题;

    原文: https://blog.csdn.net/qq_15024587/article/details/80000443 MouseArea控件大家应该是很熟悉的了.   使用起来也是非常方便的说 ...