不要用游标update a set
net = case when b.price is null then 0 else a.price-b.price end
from tab a left join tab b
on b.time = (select max(time) from tab where time<a.time)
where a.net is null
net = case when b.price is null then 0 else a.price-b.price end
from tab a left join tab b
on b.time = (select max(time) from tab where time<a.time)
where a.net is null
解决方案 »
- SQL备份的问题
- 客户端电脑在添加ODBC时出错。
- 请教一个sql语句
- 新新手求助,在线等待!!!!!!!!!!
- 字符串的分隔.
- 打开sql management studio时,选记住密码复选框不管用了??
- 100分请教数据库高手:1个存储过程中的多条删除操作和多个存储过程中各执行一个删除有何区别?
- 建数据库时,有多个数据文件,请教:数据存放到数据库时,时先存放到.mdf还是先.ndf?
- 我的windows 2000 server 一次断电导致重启后sql server 中要使用的那个数据库出现置疑状态,取消置疑状态后,系统提示日志文件出错,从而导
- 怎样在存储过程里面分页
- 求一判断
- 求助:查询表中重复记录
现在要求用sql语句实现:net的值是这一行的price减去上一行price的差值,当然第一行的net值是0,也就是说id为2的net值-0.5,id为3的net值-1.74······。
要求数据库每隔1分钟就检查一次,如果表中net值存在null值,就计算,已经计算过的就不用计算了,
-------------------为什么不在数据添加的时候做?服务器太空闲了是吧,再开个作业或线程去检查这些无谓的东西。