SQL获取连续数字中断数字
表A
-- 创建结果表
create table #u(LostA int) declare @minA int,@maxA int set @minA=(select min(ID) from A)
set @maxA=(select max(ID) from A) while(@minA<=@maxA)
begin
if not exists(select 1 from Awhere ID=@minA)
begin
insert into #u(LostA) values(@minA)
end
select @minA=@minA+1
end
select * from #u
或者
declare @minA int,@maxA int;
set @minA=(select min(ID) from A);
set @maxA=(select max(ID) from A); WITH A AS
(
SELECT @minA AS num
UNION ALL
SELECT num+1 FROM A
WHERE num<@maxA
)
SELECT num FROM A where A.num not in (select ID from A)
OPTION(MAXRECURSION 0) --当指定MAXRECURSION为0时,递归层次无限制,100为系统的默认值
SQL获取连续数字中断数字的更多相关文章
- [SQL]LeetCode180. 连续出现的数字 | Consecutive Numbers
SQL架构: Create table If Not Exists Logs (Id int, Num int) Truncate table Logs insert into Logs (Id, N ...
- sql 180. 连续出现的数字
编写一个 SQL 查询,查找所有至少连续出现三次的数字. +----+-----+| Id | Num |+----+-----+| 1 | 1 || 2 | 1 || 3 | 1 || 4 | 2 ...
- SQL查找连续出现的数字
基于Oracle: 题:编写一个 SQL 查询,查找所有至少连续出现三次的数字. +----+-----+ | Id | Num | +----+-----+ | 1 | 1 | | 2 | 1 | ...
- sql -- 获取连续签到的用户列表
签到表: 需求:统计连续签到的 用户 1.根据用户和日期分组 select user_name, sign_date from user_sign group by user_name, sign_d ...
- LeetCode:180.连续出现的数字
题目链接:https://leetcode-cn.com/problems/consecutive-numbers/ 题目 编写一个 SQL 查询,查找所有至少连续出现三次的数字. +----+--- ...
- 在SQL中取出字符串中数字部分或在SQL中取出字符部分
在SQL中取出字符串中数字部分或在SQL中取出字符部分 编写人:CC阿爸 2013-10-18 近来在开发一个项目时,一包含数字的字符串,需要取出中间的数字部分进行排序.经过baidu搜索.并结合自己 ...
- C# 获取字符串中的数字
/// <summary> /// 获取字符串中的数字(不包含小数点) /// </summary> /// <param name="str"> ...
- js验证连续两位数字递增或递减和连续三位数字相同
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- stat用法:获取文件对应权限的数字
题目:文件属性为-rw-r--r-- 对应权限为644,如何使用命令获取权限对应的数字?? 举例如下: [linuxidc@localhost ~]$ ll -l-rw-r--r-- 1 linuxi ...
随机推荐
- cos migration工具webhook推送
上一篇讲了腾讯云同步工具的使用,这篇主要是补充如何将同步结果主动消息通知. 因为cos migration 工具是java语言,并在github开源的,所以可以直接修改源码,添加webhook推送代码 ...
- [转]ArrayList的实现原理
1. ArrayList概述: ArrayList是List接口的可变数组的实现.实现了所有可选列表操作,并允许包括 null 在内的所有元素.除了实现 List 接口外,此类还提供一些方法来操作内部 ...
- pycharm加载多个项目
菜单位置:File -> Settings -> Project:xxx -> Project Stucture Project:xxx中xxx一般是已有项目的名称 窗口右侧上点击A ...
- Hive 严格模式与非严格模式
1. hive严格模式 hive提供了一个严格模式,可以防止用户执行那些可能产生意想不到的不好的效果的查询.即某些查询在严格模式下无法执行.通过设置hive.mapred.mode的值为strict, ...
- win10:如何开启自带虚拟机
1.首先要找到控制面板,我们点开windows键,然后选择在所有应用中找到“Windows 系统”,打开之后,我们找到“控制面板”,打开. 2.打开控制面板之后,我们选择程序,如图示. 3 ...
- DataGridView之DataError
解决思路一: private void dgvChargeList_DataError(object sender, DataGridViewDataErrorEventArgs e) { bool ...
- 简单说throw和throws的区别
1. 区别 throws是用来声明一个方法可能抛出的所有异常信息,throws是将异常声明但是不处理,而是将异常往上传,谁调用我就交给谁处理.而throw则是指抛出的一个具体的异常类型. 2.分别介绍 ...
- js 复制文本到剪贴板
js 复制文本到剪贴板 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- JavaScript中date日期的n种方法
转自博客 https://blog.csdn.net/u013992330/article/details/54318737
- python+selenium自动化软件测试(第3章):unittes
From: https://blog.csdn.net/site008/article/details/77622472 3.1 unittest简介 前言 (python基础比较弱的,建议大家多花点 ...