环比计算
select (tomorrowavgprice-thisday)/thisday from
(
select sum(numbers) thisday,classcode,days from tongbi GROUP BY classcode,days
)aa
left join
(
select classcode, sum(numbers) tomorrowavgprice ,DATE_ADD(days,INTERVAL 1 day ) tomorrow from tongbi GROUP BY classcode,days
)bb on aa.days=bb.tomorrow and aa.classcode=bb.classcode
select aa.classcode,aa.days,avgprice,tomorrowavgprice from
(
select classcode,avg(numbers) avgprice,days from tongbi GROUP BY classcode,days
) aa
left join
(select classcode, DATE_ADD(days,INTERVAL 1 day ) tomorrow,avgprice tomorrowavgprice from
(
select classcode,avg(numbers) avgprice,days from tongbi GROUP BY classcode,days
) bb ) cc on aa.days=cc.tomorrow and aa.classcode=cc.classcode
纯Java计算呢?
for(List list:List){
//根据索引来
比如说
比较就是list[i+1]/list[i]
list[updown]=list[i+1]/list[i];
}
//是不是也可以呢?