sql >> Base de Datos >  >> RDS >> Mysql

Fechas de la tabla dinámica de MySQL en el nombre de la columna

Simplemente puede hacer una agregación condicional:

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;