首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

求一句sql(,解决马上结帖)

2012-03-17 
求一句sql(在线等,解决马上结帖)如下表T2个字段idindex1122334455668899现在要将index 5andindex 6这2

求一句sql(在线等,解决马上结帖)
如下表T
2个字段
id     index
1       1
2       2
3       3
4       4
5       5
6       6
8       8
9       9
现在要将index> =5   and   index <=6   这2条记录的index加上一个数
这个数的值等于id=2的index的值减去id=5的index的值(这里就是2-5)
我的想法是这样的
update   T   set   index=index+(select   index   from   T   where   id=2)-(select   index   from   T   where   id=5)   where   index   between   5   and   6

请教高手要怎么写才能实现这个效果

[解决办法]
try


update T , (select index from T where id=2) A, (select index from T where id=5) B set T.index=T.index+A.index-B.index where T.index between 5 and 6

热点排行