SQL|SQL 查找缺失的序号
SELECT D1.digit + (D2.digit*10) AS seq
FROM Digits D1 CROSS JOIN Digits D2
ORDER BY seq;
SELECT D1.digit + (D2.digit10) + (D3.digit100) AS seq
FROM Digits D1 CROSS JOIN Digits D2 CROSS JOIN Digits D3
WHERE seq BETWEEN 1 AND 542
ORDER BY seq;
CREATE VIEW Sequence (seq)
AS SELECT D1.digit + (D2.digit10) + (D3.digit100)
FROM Digits D1 CROSS JOIN Digits D2 CROSS JOIN Digits D3;
CREATE VIEW Sequence (seq)
AS SELECT D1.digit + (D2.digit10) + (D3.digit100) + (D4.digit*1000)
FROM Digits D1 CROSS JOIN Digits D2 CROSS JOIN Digits D3 CROSS JOIN Digits D4;
SELECT seq FROM Sequence WHERE seq BETWEEN 0 AND 4999
EXCEPT
select cast(substr(user_name, 10) as int) as seq from user_info where user_name like ‘test_user%’
【SQL|SQL 查找缺失的序号】参考:
《SQL进阶教程》1.9
推荐阅读
- py连接mysql
- 2019-01-18Mysql中主机名的问题
- 一个农民的初心!
- MySql数据库备份与恢复
- mysql|InnoDB数据页结构
- 数据库|SQL行转列方式优化查询性能实践
- mysql中视图事务索引与权限管理
- MYSQL主从同步的实现
- MySQL数据库的基本操作
- javaweb|基于Servlet+jsp+mysql开发javaWeb学生成绩管理系统