use information_schema;
select table_name,table_rows from tables
where TABLE_SCHEMA = 'test'
order by table_rows desc;
The above is the existing query statement, which can find all the tables in the entire database and how much data is in the table.
Now I want to break it down:
For example, there are 1,000 tables in the test database, and I only want to check 200 of them (specified) Contain the specified date (with the date field, The type is mediumtext) and how many pieces of data there are.
How to write this kind of query statement?
-----------------Modified question----------------------
I can’t express it clearly, so I’ll describe it again:
As shown above, I have many tables in the test database, and each table has a lot of data. Each table has a field "time", the type is mediumtext, such as 2017-5-9 16:44:24.
I want to query multiple tables at one time to see how many pieces of data each table has that contains the specified "time" (2017-5-9).
过去多啦不再A梦2017-05-18 10:51:37
use information_schema;
select table_name,table_rows from tables
where TABLE_SCHEMA = 'test' and TABLE_NAME in ('Specification 1','Specification 2',.......,'Specification 200') and UPDATE_TIME = 'Specification Time'
order by table_rows desc;
给我你的怀抱2017-05-18 10:51:37
The author is talking about finding the table containing the date field of the specified type, right? information_schema also has a columns table, and you can do a joint query
select a.table_name,a.table_rows from tables a join columns b on a.table_name=b.table_name and a.table_schema=b.table_schema
where a.TABLE_SCHEMA = 'test' and b.DATA_TYPE='mediumtext' and COLUMN_NAME='指定日期字段'
order by table_rows desc;