56,678
社区成员
发帖
与我相关
我的任务
分享
drop table if exists tb;
create table tb(col1 int auto_increment key, col2 int) as select 0 as col2 from information_schema.tables limit 10;
update tb set col2=col1+1;
select * from tb;
update tb a, (
select a.col1, a.col2 - ifnull(b.col2,0) as col2
from(
select col1, @id1:=@id1+1 as id, @col21:=@col21+col2 as col2 from tb, (select @id1:=0, @col21:=0) x
order by col1
)a left join(
select col1, @id:=@id+1 as id, @col2:=@col2+col2 as col2 from tb, (select @id:=0, @col2:=0) x
order by col1
) b on a.id = b.id + 3
) b
set a.col2=b.col2
where a.col1=b.col1;
select * from tb;
update tb, tb b set tb.col2 = tb.col2+b.col2 where tb.col1=b.col1+1
2
3
update tb a, (select col1, (select sum(b.col2) from tb b where b.col1<=a.col1) as col2 from tb a order by a.col1 desc limit 2) b
set a.col2=b.col2
where a.col1=b.col1;
update tb a, (select col1, (select sum(b.col2) from tb b where b.col1<=a.col1) as col2 from tb a) b
set a.col2=b.col2
where a.col1=b.col1;