我不确定这是否可能,但我正在尝试插入,同时选择一个值来做 +1。我这样做的原因是因为我的列是自动递增的,但是值到处都是。
这是我到目前为止所拥有的,它不会让我插入:
insert into channels set chanid=(select chanid from channels where parent=2
order by chanid desc limit 1)+1
insert into channels(chanid)
select chanid+1 from channels where parent=2
order by chanid desc limit 1
尝试在子查询中使用别名。它对我有用。
insert into channels
set chanid=(
select c.chanid
from channels as c
where c.parent=2
order by c.chanid desc
limit 1
)+1
如果我理解正确你的问题试试这个!
insert into channels set chanid=(select chanid+1 from channels where parent=2 order by chanid desc limit 1)
要重置auto-increment
值,您可以尝试
SET @var_count = 0;
UPDATE channels
SET chanid = (@var_count := @var_count + 1);
或者
删除auto-increment
列并在其PRIMARY KEY
上重新创建它。