gpt4 book ai didi

mysql - 如果值为 null ,如何在所有行中设置值,使用 Max 中的值

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

我有一张 table ,客户
我的表格是“客户”4 列

CusttomerId  Name   ContactName Country
1 Shere1 Ira USA
2 Shere2 Jenny Canada
3 Shere3 Fill Canada
4 Prod1 Joen China
Null Prod2 Clod Russia
Null Prod3 Brenda Finland
Null Prod4 Katy Belgium

CustomerId列中,我需要将所有行的值设置为空。例如,在 CustomerId = 4 之后,下一个值必须是 CusttomerId = 5 ,下一行 CustomerId = 6 ...

请帮助我。

最佳答案

您可以尝试使用 mysql 变量并通过查询 max() 分配初始值

set @id := (select max(CusttomerId) from  Customers)
;
update Customers
set CusttomerId = (@id :=@id +1 )
where CusttomerId is null
;

关于mysql - 如果值为 null ,如何在所有行中设置值,使用 Max 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55771825/

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