我需要获取 2014 年尚未分区的所有表的数据库和表列表。
我正在考虑查询满足以下条件的information_schema
.PARTITIONS
:
PARTITION_NAME IS NOT NULL
PARTITION_NAME='p201312'
AND PARTITION_NAME !='p201401'
我如何查询这个。我试过:
select DISTINCT * FROM(select `TABLE_SCHEMA`, `TABLE_NAME` from `information_schema`.`PARTITIONS` where PARTITION_NAME IS NOT NULL AND PARTITION_NAME='p201312' AND PARTITION_NAME!='p201401') as a;
但是不起作用。请帮忙。
* 更新 **
我能够组合一个查询来获得我需要的内容:
SELECT a.
TABLE_SCHEMA
, a.TABLE_NAME
FROM (selectTABLE_SCHEMA
,TABLE_NAME
frominformation_schema
.PARTITIONS
where PARTITION_NAME='p201312') as a LEFT JOIN (selectTABLE_SCHEMA
,TABLE_NAME
frominformation_schema
.PARTITIONS
where PARTITION_NAME='p201401') as b ON a.TABLE_NAME
= b.TABLE_NAME
WHERE b.TABLE_NAME
IS null;
有没有办法让这个查询更优雅一点?
最佳答案
select
table_schema,
table_name
from
information_schema.tables t
where
not exists (
select
null
from
information_schema.partitions p
where
p.table_schema = t.table_schema and
p.table_name = t.table_name and
p.partition_name like 'p2014%'
)
关于Mysql准备做2014年每月分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20078222/