我需要获取尚未为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;
但是不起作用。请帮忙。
*更新**
我能够整理一个查询以获得我需要的东西:
选择a。
TABLE_SCHEMA
,a。TABLE_NAME
FROM(从TABLE_SCHEMA
选择TABLE_NAME
,information_schema
。PARTITIONS
,其中PARTITION_NAME ='p201312 ') 作为一个 LEFT JOIN(从TABLE_SCHEMA
。TABLE_NAME
选择information_schema
,PARTITIONS
,其中PARTITION_NAME ='p201401')为b ON a。TABLE_NAME
= b。TABLE_NAME
WHERE b。TABLE_NAME
为空;
有没有办法让这个查询更优雅?
答案 0 :(得分:0)
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%'
)