我尝试使用从所述列中的1 + max值开始的增量计数器更新多行中的列,因此:
原件:
fkey | fval
--------------
one | 1
two | 2
three | 3
four | 4
five | 5
six | 6
seven | 7
伪代码:
update tabA set fval = (select max(fval) from tabA)+counter(1)
where fkey in ('two', 'six', 'four');
-- counter starts at 1 and increments for each value
所需:
fkey | fval
--------------
one | 1
two | 8
three | 3
four | 10
five | 5
six | 9
seven | 7
如何在Sqlite中完成(有效)?
上下文:我试图在表行上运行队列,此操作会将行列表移到前面(同时也保持其相对顺序)。
编辑:尝试1:
尝试使用计数器视图,但由于仅使用了第一个增量,因此失败:
with recursive cnt(r) as (select 1 union all select r+1 from cnt)
update taba set fval= (select r from cnt)+(select max(fval) from taba)
where fkey in ('two', 'six', 'four');
sqlite> select * from taba;
one|1
two|8
three|3
four|8
five|5
six|8
seven|7
答案 0 :(得分:0)
只要唯一的要求是新数字更大,您只需在所有这些行中为旧值添加足够大的值:
UPDATE tabA
SET fval = fval + (SELECT MAX(fval) FROM tabA)
WHERE fkey IN ('two', 'six', 'four')
答案 1 :(得分:0)
<input type="submit" class="button blue" value="&##xf003; Contact Me">