2016-08-02 30 views
-1

我有表的列表:獲取SQL最大插入日期使用連接

select tableList 
from information_schema.tables 

每個表都有一個插入日期。我想每個表中的最大值(insertdate),並把插入日期就在旁邊,如:

Column1 Column2 
table1 MaxInsertDateTable1 
table2 MaxInsertDateTable2 
table3 MaxInsertDateTable3 
table4 MaxInsertDateTable4 

有沒有辦法做到這一點?我使用的是MPP數據庫:

http://www.actian.com/products/big-data-analytics-platforms-with-hadoop/matrix-mpp-analytics-databases/

回答

0

我會設想一個查詢,如:

select 'table1' as column1, max(insertdate) as column2 from table1 union all 
select 'table2' as column1, max(insertdate) as column2 from table2 union all 
select 'table3' as column1, max(insertdate) as column2 from table3 union all 
select 'table4' as column1, max(insertdate) as column2 from table4;