How to query the horizontal table?

to query the data after horizontal split, suppose the data of a business is split horizontally, and the monthly records are stored in a table. The data of each table is about 1000w. There are already more than 20 tables, such as table_201606,.,table_201702.table_201804 . If you need to query the data from July 2016 to March 2018, how to query it? Performance and query speed need to be considered.


there is no special way to do this, do a query for each single table, and then summarize the result set.

can be a dynamically generated statement with union, or you can cycle through the application to query a single table and then merge the result sets.


isn't the year behind your table? Use PHP to first assemble the table to be queried, and then summarize the data. Another way is to query the main table according to the rules of your horizontal table. Just choose one of the two methods

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3984c-4ee05.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3984c-4ee05.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?