Mysql实战之快速填充序列维度表
2023-09-14 09:13:14 时间
Mysql实战案例五之快速填充序列维度表
1.需求
2.代码
3.执行效果
4.
create table nums(
a int UNSIGNED not null primary key
)engine = INNODB;
create procedure createNums(cnt int UNSIGNED)
begin
declare s int UNSIGNED DEFAULT 1;
truncate table nums;
while s <= cnt
do
begin
insert into nums select s;
set s=s+1;
end;
end while;
end;
call createNums(100)
drop PROCEDURE if EXISTS createNums;
create procedure createNums(cnt int UNSIGNED)
begin
declare s int UNSIGNED DEFAULT 1;
truncate table nums;
insert into nums select s;
while s *2 <= cnt
do
begin
insert into nums select a+s from nums;
set s=s*2;
end;
end while;
end;
call createNums(200000)
select count(*) from nums;
-- 选择一个从start -> end 的递增日期
create procedure createDimTime(start Date,end Date)
BEGIN
select DATE_ADD(start,INTERVAL a-1 day)
from nums where a<=DATEDIFF(end,start)+1;
end;
call createDimTime('2018-09-02','2018-09-10')
相关文章
- Mysql 5.7 索引使用规则和设计优化
- 【Mysql 学习】mysql 字符集
- 磁盘爆满导致MySQL无法启动:Disk is full writing './mysql-bin.~rec~' (Errcode: 28). Waiting for someone to free space...
- 【Mysql安装】Mac下安装mysql
- 【异常】ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock
- 【问题解决方案】MySQL安装后无法启动-net start mysql服务名无效
- 怎样保证mysql备库slave只读(授权)
- 使用mysql-connector-python操作MYSQL数据库
- 【问题解决方案】MySQL安装后无法启动-net start mysql服务名无效
- 你还在 Docker 中跑 MySQL?
- Java Spring里com.mysql.jdbc.Driver的加载时机
- [转]MySQL事务学习-->隔离级别
- error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
- mysql常用基础操作语法(十)~~子查询【命令行模式】
- 【数据库系统】SQLite vs MySQL vs PostgreSQL:关系数据库管理系统的比较
- select加锁分析(Mysql)
- mysql编码和Java编码相应一览表
- 【MySQL】面试官:如何添加新数据库到MySQL主从复制环境?
- [MySQL] 解决办法: Error: Transaction test error: file /etc/my.cnf from install of mysql-community-server
- MySQL 数据库常用命令 超级实用版分享
- mysql select into outfile默认文件保存路径是C:ProgramDataMySQLMySQL Server 8.0Data
- MYSQL提权之反弹SHELL——数据库提权属于webshell到管理员的纵向提权,本质还是利用udf提权,无非是在mysql自定义函数中使用了反弹shell而已
- MySQL — 利用命令:获取系统当前时间、打开系统服务、Mysql命令界面快速回到之前的语句
- [MySQL] 解决办法: Error: Transaction test error: file /etc/my.cnf from install of mysql-community-server