逐月累计订单数量
set @order_num = 0;
SELECT (@order_num := @order_num + t.totalOrder) AS tnum
FROM(
select IFNULL(tso.totalPay,0) AS totalOrder
from month_view mv
LEFT JOIN (
SELECT
DATE_FORMAT(tso.add_time,'%Y-%m') yearMonth,
SUM(tso.num) totalPay
FROM t_sale_order tso
WHERE tso.delete_flag = 0
AND DATE_FORMAT(tso.add_time,'%Y-%m') > DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 12 MONTH),'%Y-%m')
GROUP BY yearMonth
) tso ON mv.mon = tso.yearMonth
GROUP BY mv.mon
) t
这是两条sql语句,在代码中,应该是两个xml语句
set 设置初始值为0
month_view 为查询近十二个月的视图,上篇博客中的内容
t_sale_order 为销售订单表