Py学习  »  DATABASE

插入到mysql的非插入

Tom • 3 年前 • 1122 次点击  

我在下面的语句中插入了mysql。当我单独运行select语句时,它会产生结果。

下面是表的Create语句

**create table if not exists analyze_checks(dbname varchar(50),table_name  varchar(50),frag_ratio decimal, days integer,needs_optimization char(3),needs_analyzing char(3)) ENGINE=INNODB**
**insert into analyze_checks(dbname,table_name,frag_ratio, days,needs_optimization,needs_analyzing ) 
(select 
'test' as dbname,
table_name,
frag_ratio,
days,
needs_optimization,
needs_analyzing
from 
(select 
table_name, 
cast(frag_ratio as decimal(5,2)) as frag_ratio, 
days,
case when frag_ratio > 1 then 'Yes' else 'No' end as needs_optimization,    
case when days > -1 then 'Yes' else 'No' end as needs_analyzing 
from (
select  
t.ENGINE,   
concat(t.TABLE_SCHEMA, '.', t.TABLE_NAME) as table_name,    
round(t.DATA_FREE/1024/1024, 2) as data_free,   
(t.data_free/(t.index_length+t.data_length)) as frag_ratio,  
datediff(now(), last_update) as days 
FROM information_schema.tables t 
left join mysql.innodb_table_stats s on t.table_name=s.table_name 
WHERE DATA_FREE > 0 ORDER BY frag_ratio DESC )d ) d 
where needs_optimization='Yes' or needs_analyzing='Yes');**
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131595
 
1122 次点击  
文章 [ 1 ]  |  最新文章 3 年前