How to use a msyql statement to put several tables with the same table structure into a table and finally export it?

I now have multiple tables that generate one table every day from July 1 to December 30, and now my boss asks me to summarize the table contents of each month. The database table is just like in the picture. I wonder if it is possible to use a SQL statement wildcard or even a table statement to list the data of each month separately. What I see is that this daily table is generated by rules. I don"t know which hero can instruct me to thank myself for writing SELECT FROM mas_sms_sent_2018_07_06 UNION SELECT FROM mas_sms_sent_2018_07_09 UNION SELECT FROM mas_sms_sent_2018_07_10 UNION select FROM mas_sms_sent_2018_07_12;. The content is what I want, but I think 30 days means I have to 30 times and then summarize it into July. What if the boss doesn"t like it and asks me to summarize what to do for a year? my stupid method certainly won"t work, so I would like to ask all of you to help me to see if it is best to generate an AS table for July, but my mysql is half a bucket of water. For example, AS table name (qiyue) ![][2]

Jan.08,2022

since you can achieve it for a month, you might as well write a script that can change the sql statement according to the passed parameters and change the corresponding time. Every time the boss asks you to guide, you execute the file, and then pass in the time your boss gives you. Will it be more convenient, a rookie, and do not scold if there is no good way!


it is recommended that the master write the stored procedure. You can write a for loop to concatenate the strings of the table name.


who makes your boss unhappy? ha ha
has been divided into daily tables, so it can only be union.
if you want to make it easier, transform these tables into partitioned tables, one partition a day according to the time field in the table. In this way, the management is not much different from the daily watch, when you need to check the data, you only need to use the time field to limit the scope, one month, one year, half a year, whatever you want. Build an index on the time field, and you can run more comfortably.


this is heterogeneous storage.
you can listen to musql binlog, to write all the data to a table and then read it from that table. The implementation can use Alibaba's open source canal.

Menu