Mysql
 sql >> Base de données >  >> RDS >> Mysql

Dates du tableau croisé dynamique MySQL sur le nom de la colonne

Vous pouvez simplement faire une agrégation conditionnelle :

select table_name,
       max(case when date = '2016-09-14' then round(((data_length + index_length) / 1024 / 1024), 2) end) as size_20160915,
       max(case when date = '2016-09-15' then round(((data_length + index_length) / 1024 / 1024), 2) end) as size_20160916,
       (max(case when date = '2016-09-15' then round(((data_length + index_length) / 1024 / 1024), 2) end) -
        max(case when date = '2016-09-14' then round(((data_length + index_length) / 1024 / 1024), 2) end)
       ) as diff
from DBA_DB.table_growth_history t
where date in ('2016-09-14', '2016-09-15')
group by table_name;