当前位置:网站首页>Get all table names and table names with time strings in Mysql Use BetweenAnd to filter the interval range
Get all table names and table names with time strings in Mysql Use BetweenAnd to filter the interval range
2022-08-07 10:02:00 【Domineering rogue temperament】
Scenario
SpringBoot+Mybatis realizes the code to obtain the table building statement and realize dynamic table building:
Based on the dynamic table creation above, a table will be generated in the database every day as follows

Then how to get all the table names in the code, and query the table names within this period according to the time interval.
Note:
Blog:
DomineeringA blog with rogue temperament
Implementation
1. Query the sql of all table names in Mysql
SELECT table_name FROM information_schema.TABLES WHERE table_schema = (select database())
where to get the names of all tables
SELECT table_name FROM information_schema.TABLESTo get the name of the table from a specific database
SELECT table_name FROM information_schema.TABLES WHERE table_schema = ''Get the current database name
select database()2. Now what we need is to query the data within the specified range according to the automatically generated table name with time string
For example, we only need two table names, bus_badao_record20220804 and bus_badao_record20220805.
You can use the Between And statement.
If the compared field is a string in time format, the data in the corresponding range can be automatically filtered out.
For verification, create a new test table

The date field is of varchar type, and then to filter out the data in the range from 20220804 to 20220805, you can write like this
SELECT date from badao where date between '20220804' and '20220805'
Not only that, if you add the same prefix to each data, the filtering effect can still be achieved
SELECT date from badao where date between 'badao20220804' and 'badao20220805'
So the table name within the specified range of the filter above can be written like this
SELECT table_name FROM information_schema.TABLES WHERE table_schema = (select database()) AND table_name BETWEEN 'bus_badao_record20220804' AND 'bus_badao_record20220805'
边栏推荐
猜你喜欢

The 900-page mathematical paper proves that the rotating black hole will not explode, Chengtong Yau: The first major breakthrough in general relativity in more than 30 years...

For high-performance, ultra-large-scale model training, this combination "debuts"

4.2 实现注册与登录模块

【C语言】汉诺塔

Mysql中获取所有表名以及表名带时间字符串使用BetweenAnd筛选区间范围

The non-professional AI brother is on fire: he doesn't have an ML degree, but he got an offer from DeepMind

China's mobile phones continue to innovate, and the full screen goes further, leading mobile phone innovation

解决typora的文件内容复制到csdn上图片显示不出来的问题

世界上最大的开源基金会 Apache 是如何运作的?
![[Punctuality Atom STM32 Serial] Chapter 6 New Register Version MDK Project Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1](/img/6e/c02ecc2703a20879aaecbf8a75ff70.png)
[Punctuality Atom STM32 Serial] Chapter 6 New Register Version MDK Project Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
随机推荐
Go语言的其他高级特性
leetcode 26. 删除有序数组中的重复项(实现unique函数)
npm 发布问题
xlwings模块(数据保存为xlsx文件)
[Go] (1) Go language development environment configuration
这种调试方法,你值得拥有
牛客多校-Eezie and Pie-(倍增+树上差分)
Excel export operation based on ABP and Magiccodes
命令执行漏洞
UGUI系列-InputField限制输入个数以及限制输入格式
unity打包webgl 部署到本地Web服务器
解决typora的文件内容复制到csdn上图片显示不出来的问题
Niu Ke Duo School-Z-Game on grid- (Game Theory + Must-win and must-defeat transfer)
100天精通Andriod逆向——第1天:ADB原理及其常用命令
数据可视化(三)
3.ROS通信机制进阶
What is an SRM system?What is the role? How does the enterprise apply the SRM system?
你知道12306 是如何支撑百万 QPS 的?
thinkphp 6.x arbitrary file write vulnerability
项目优化之光照使用(Unity3D)