In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
In view of how to select from a relationship goal that will be updated in MySql, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
How to select from a relationship goal that will be updated in MySql:
+-+
| | account_number | branch_name | balance | |
+-- +
| | Amuri 101 | Downtown | 500.00 | |
| | Amuri 102 | Perryridge | 400.00 | |
| | Alam 201 | Brighton | 900.00 | |
| | AME 215 | Mianus | 700.00 | |
| | Amure 217 | Brighton | 750.00 | |
| | Amura 222 | Redwood | 700.00 | |
| | AMEL 305 | Round Hill | 350.00 | |
+-+-- +-+
Updateaccount
Setbalance = balance * 1.05
Wherebalance > (select avg (balance))
Fromaccount)
And then I made a mistake! Is there any! It is as follows:
Youcan't specify target table 'account' for update in FROM clause.
The mistake is that you cannot point to and select a target relationship that will be modified or updated.
Http://dev..com/doc/refman/5.0/en/update.html wrote:
"Currently,you cannot update a table and select from the same table in asubquery."
But in many cases, I want to update a relationship with some data that happens to be obtained through a subquery pointing to that relationship. For example, in this example, I need an aggregate function to calculate the balance mean of account.
Solution:
MySQL materializes the derivative relation (derivedtable) of the subquery of the from clause into a temporary table (temporarytable), so we can insert (selectavg (balance) from account) into another from clause:
Updateaccount
Setbalance = balance * 1.05
Wherebalance > (select avg (tmp.balance))
From (select * from account) as tmp
)
This is the answer to the question about how to select from a relationship goal that will be updated in MySql. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.