我写数据集求同比select T1.orderTime, t1.PROVINCE, t1.CITY, t1.num 本期订单量, t2.num 上期订单量, round(t1.num/t2.num-1,4) 同比from (select *from (select cast(orderTime as date)orderTime,province,city,numfrom(select concat('20',from_unixtime(o.created , '%y-%m-%d')) as orderTime,o.province,o.city,count(o.city) num from `order` o join shop sh on o.shop_id=sh.id where 1=1 /*and o.status=99 订单完成*/ and pay_status=2 /*支付成功*/ group by orderTime,o.province,o.city having num>0 )aa)bbwhere orderTime between '${tstart1}' and '${tend1}')t1left join (select *from (select cast(orderTime as date)orderTime,province,city,numfrom(select concat('20',from_unixtime(o.created , '%y-%m-%d')) as orderTime,o.province,o.city,count(o.city) num from `order` o join shop sh on o.shop_id=sh.id where 1=1 /*and o.status=99 订单完成*/ and pay_status=2 /*支付成功*/ group by orderTime,o.province,o.city having num>0 )aa)bbwhere orderTime between '${YEARDELTA(tstart1,-1)}' and '${YEARDELTA(tend1,-1)}')t2on t1.PROVINCE=t2.PROVINCE and t1.CITY=t2.CITY正确的数据应该是这样的:左连接以后 数据变成了这样