gpt4 book ai didi

mysql - 更新同一个表中值为最大值的位置

转载 作者:行者123 更新时间:2023-11-29 07:14:13 30 4
gpt4 key购买 nike

我想做这个。

update cart set productname='hey' where cartid=(select max(cartid) from cart)

但是,sql 显示表“cart”定义两次的错误。我该如何解决这个问题?

最佳答案

在 MySQL 中,您可以将 updatelimit 一起使用:

update cart
set productname = 'hey'
order by id desc
limit 1;

您可以查看文档 here .

如果要计算值,可以使用join:

update cart c join
(select max(id) as maxid from card) cc
on c.id = cc.maxid
set productname = 'hey';

如果多行可能具有最大 ID 并且您希望更新所有行,这将特别有用。

关于mysql - 更新同一个表中值为最大值的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38544340/

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