gpt4 book ai didi

MySQL 使用 max 函数通过子查询更新查询

转载 作者:行者123 更新时间:2023-11-29 09:29:23 32 4
gpt4 key购买 nike

谁能看出下面的查询有什么问题吗?

update sub set name='dd' where salary=(select max(salary) from sub);

执行后发现错误并且 MariaDB 表示,

SQL query: Documentation

update sub set name='dd' where salary=(select max(salary) from sub)

MySQL said: Documentation

\ #1093 - Table 'sub' is specified twice, both as a target for 'UPDATE' and as a separate source for data

最佳答案

MySQL 不允许这种语法。您可以使用 join 来代替:

update sub s
inner join (select max(salary) salary from sub) m on m.salary = s.salary
set s.name = 'dd'

关于MySQL 使用 max 函数通过子查询更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59022256/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com