Ask the writing method of this SQL statement. at last, the basic conditions for editing are: user table & nbsp; userid & nbsp ;, username & nbsp; user_money & nbsp; description of this SQL statement in table & nbsp
At the end of this post, the basic conditions are edited by u042569689 at 18:25:00:
Userid, username
User_money table u_id, user_money
User_money_exchange table: money, username, ordertag = 1 or 2
Now you want to execute:
Update user_money set user_money = (user_money_exchange when ordertag = 1 sum (money) + when ordertag = 2 sum (money) where user_money.u_id = user. userid
update user_money
set user_money.money =
(select sum(ume.money) as m , u.userid from user_money_exchange ume left join user u on ume.username = u.username where ume.ordertag = 1 group by ume.username
+
select sum(ume.money) as m , u.userid from user_money_exchange ume left join user u on ume.username = u.username where ume.ordertag = 2 group by ume.username)
where user_money.u_id = u.userid
This is wrong. Is it true? Thank you for sharing SQL select update:
------ Solution --------------------
Try
update user_money um left join user u on um.u_id=u.userid
left join
(select username,sum(money) as moneys from user_money_exchange group by username) ume
on ume.username=u.username
set um.money = ume.moneys