Ask how this SQL is written and how to handle it

Source: Internet
Author: User
Ask this SQL for the wording
This post was last edited by u011669689 on 2013-09-25 18:25:00

Basic conditions:
User Table UserID, username
User_money Table U_id,user_money
User_money_exchange table: Money, Username,ordertag = 1 or 2

Now want to do:

Update User_money Set User_money = (User_money_exchange when Ordertag =1 's sum (money) + when Ordertag =2 's sum (money)) where User_mo ney.u_id = User.userid






(select SUM (Ume.money) as M, U.userid from User_money_exchange Ume left join user u on ume.username = U.username wher e Ume.ordertag = 1 GROUP BY Ume.username

Select SUM (Ume.money) as M, U.userid from User_money_exchange ume

where user_money.u_id = U.userid



This is wrong, and you want to know what's right? Thank you, everyone. SQL Select Update

Share to:


------Solution--------------------
Give it a 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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.