select createDay,max(orderNum) as orderNum,max(payment) as payment from( SELECT @cdate := DATE_ADD( @cdate, INTERVAL - 1 DAY ) `createDay`, 0 AS `orderNum` ,0 as payment FROM ( SELECT @cdate := DATE_ADD( #{endAt}, INTERVAL + 1 DAY ) FROM tb_order_order ) t1 where @cdate > #{startAt} //统计日期 union all select DATE_FORMAT(pay_at,'%Y-%m-%d') as createDay,count(order_id) as orderNum,sum(payment)as payment from tb_order_order where shop_id = #{shopId} and status in (2,3,4,5,7) and pay_at between #{startAt} and #{endAt} group by createDay order by createDay desc ) as tmp //统计订单 group by createDay asc