有没有办法在 MySQL 更新查询中计算 Int?
目前我有
UPDATE mails SET uid = 4275
我想要类似的东西
UPDATE mails SET uid = (4275++)
有没有办法在 MySQL 更新查询中计算 Int?
目前我有
UPDATE mails SET uid = 4275
我想要类似的东西
UPDATE mails SET uid = (4275++)
你想做这样的事情吗?
SELECT @i:=425;
UPDATE mails SET uid = @i:=@i+1;
如果您需要更新表以使每个表增加uid
1,那么您可以这样做:
UPDATE mails
SET uid = uid + 1;
但是,如果您需要将每个值uid
增加一个增量值,请尝试以下操作:
SET @counter = 0;
UPDATE mails m1
INNER JOIN
(
SELECT *, (@counter := @counter +1) as counter
FROM mails
) m2 ON m1.uid = m2.uid
SET m1.uid = m1.uid + m2.counter
如果你想从 4275 开始计数,只需将计数器设置为SET @counter = 4275
更新邮件 SET uid = uid + x
x 表示任何数字
我没有正确回答您的问题,但我只是按照我的理解回答
更新邮件 SET uid = uid + 1
即通过lastuid + 1增加当前uid
UPDATE mails SET uid = uid +1
将为每个 uid 列添加 1。
尝试
UPDATE mails SET uid = uid+1
where uid = 4275
您可以保留自己的柜台
declare @curr_uid integer;
SET @curr_uid = 4275; -- initial uid
update mails
set uid = @curr_uid , @curr_uid = @curr_uid + 1