sql -- 多表关联,update(用户奖励)
表设计:
users_buy:
users_score:
需求:
1.根据用户分组,找出用户消费最高的金额
select user_name, max(paymoney) as pm from users_buy group by user_name;
2.更新他们的余额
update users_score a inner join (select user_name, max(paymoney) as pm from users_buy group by user_name) b on a.user_name = b.user_name set a.user_score=a.user_score + (b.pm * 0.1);