Mysql
 sql >> Database >  >> RDS >> Mysql

Date della tabella pivot MySQL sul nome della colonna

Puoi semplicemente fare l'aggregazione condizionale:

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;