Mysql准备做2014年每月分区

标签 mysql sql partitioning information-schema

我需要获取 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 (select TABLE_SCHEMA, TABLE_NAME from information_schema.PARTITIONS where PARTITION_NAME='p201312') as a LEFT JOIN (select TABLE_SCHEMA, TABLE_NAME from information_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/

相关文章:

mysql - MySQL 中何时使用单引号、双引号和反引号

php - 模型 CakePHP 中的多个(分片)表

python - sqlalchemy.exc.OperationalError : Can't connect to mysql in docker

php - 根据ID获取mysql数组的乘积

sql - T-SQL 分组依据;包含或如果有

sql - 在 Postgres 中的数组字段中搜索

mysql - 使用函数的 SQL VIEW (phpMyadmin)

ruby-on-rails - 一个 Rails 应用程序可以使用多个 Redis 实例吗?

postgresql - 在 PostgreSQL 表继承中选择

java - Spring批量分区: Slave step with multiple steps