同比:
select
t5.m,FORMAT(((t5.newhan-t5.oldhan)/t5.oldhan)*100,2)
from
(
select t3.month as m,t3.avg_han as newhan,t2.avg_han1 as oldhan
from
(select date_format(time, '%Y-%m') as month,avg(han) as avg_han
from hanni group by month) t3
left join
(
select date_add(t1.month,INTERVAL 1 YEAR) as last_month,t1.avg_han as avg_han1
from
(select date_format(time, '%Y-%m') as month,avg(han) as avg_han
from hanni group by month) t1
) t2
on t3.month=t2.last_month
) t5
环比:
select
t5.m,FORMAT(((t5.newhan-t5.oldhan)/t5.oldhan)*100,2)
from
(
select t3.month as m,t3.avg_han as newhan,t2.avg_han1 as oldhan
from
(select date_format(time, '%Y-%m') as month,avg(han) as avg_han
from hanni group by month) t3
left join
(
select date_add(t1.month,INTERVAL 1 MONTH) as last_month,t1.avg_han as avg_han1
from
(select date_format(time, '%Y-%m') as month,avg(han) as avg_han
from hanni group by month) t1
) t2
on t3.month=t2.last_month
) t5;