像这种sql语句的核心是:建立目标字段之间的关系映射表,中间依靠各种中间临时表来搭建
#复杂sql语句
update business b,(
#建立商户与星级的对应关系表
select o.business_id,sum(a.star) totalStar,count(*) totalComment from orders o,
#订单编号与star的对应关系表
(select order_id,star from `comment` where createTime<=now())a
where o.id=a.order_id group by o.business_id
)temp
set b.star=b.star + temp.totalStar,b.commentNum=b.commentNum+temp.totalComment where b.id=temp.business_id;