sql计算语句

sjshuang 2008-05-16 11:40:33
A表
在第X行中A.BB=20
在第X+1行中A.dd=20*10
谁会写这个sql语句?
...全文
137 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pt1314917 2008-05-16
  • 打赏
  • 举报
回复
什么意思?
sjshuang 2008-05-16
  • 打赏
  • 举报
回复
X
是未知数
skyzcl 2008-05-16
  • 打赏
  • 举报
回复
select id= identity(int,1,1),* into # from a

update # set bb=20 where id=X
update # set dd=20*10 where id=X+1


swot2008 2008-05-16
  • 打赏
  • 举报
回复
declare curupdate cursor static for
select id from A
fetch next from curupdate into @id
open curupdate
select @bb = isnull(bb,0) from A where id = (select max(id) as id from A where id < @id)
update A set dd = @bb*10 where id = @id
fetch next from curupdate into @id
close curupdate
deallocate curupdate
sjshuang 2008-05-16
  • 打赏
  • 举报
回复
行号只能知道是上一行,具体的那行就不知道了
Herb2 2008-05-16
  • 打赏
  • 举报
回复
是这样?????
update a set bb= 20,dd=20*10

zanyzyg 2008-05-16
  • 打赏
  • 举报
回复

应该能确定行号吧?

update A表
set dd=isnull((select a.bb from A表 where id=t.id-1)*10,dd)
from A表 t
wzy_love_sly 2008-05-16
  • 打赏
  • 举报
回复
declare @tb table (id int identity(1,1),num1 int,num2 int)
insert into @tb(num1) select 1
insert into @tb(num1) select 2
insert into @tb(num1) select 5
insert into @tb(num1) select 7

update t set num2=(select sum(num1) from @tb where id<=t.id) from @tb t
select * from @tb


id num1 num2
1 1 1
2 2 3
3 5 8
4 7 15
zanyzyg 2008-05-16
  • 打赏
  • 举报
回复


应该能确定行号吧?

update A表
set a.dd=(select a.bb from A表 where id=t.id-1)*10
from A表 t


34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧