mysql 查询将字段更新为 max(field) + 1
我想做的是:
UPDATE table SET field = MAX(field) + 1 WHERE id IN (1, 3, 5, 6, 8);
在我看来,这个语句的语义首先是数据库会启动并为我确定所有表中
。然后,它会将该值加 1,并将结果值分配给 field
的最大值是多少id
1、3、5、6 和 8 的行的 field
列。看起来很简单够了...
当我尝试运行该查询时,MySQL 窒息了并说:
ERROR 1111 (HY000): Invalid use of group function
你必须使用什么秘密武器才能获得我想要的结果?
问候, 维克
What I want to do is:
UPDATE table SET field = MAX(field) + 1 WHERE id IN (1, 3, 5, 6, 8);
The semantics of this statement, in my mind, would be first the database would go off and determine for me what the largest value of field
is in all of table
. It would then add 1 to that value, and assign the resulting value to the field
column of the rows with id
1, 3, 5, 6, and 8. Seems simple enough...
When I try to run that query though, MySQL chokes on it and says:
ERROR 1111 (HY000): Invalid use of group function
What's the secret sauce you have to use to get the outcome I desire?
Regards,
Vic
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Try
为了解决
mysql-error-1093
,请使用子查询/派生表/内联视图:In order to get around the
mysql-error-1093
, use a subquery/derived table/inline view: