求一条SQL语句
在 表 xx 中
id reyuan shijan
1 1 2006-5-19 14:00
2 1
3 1
4 1
5 2
6 2
7 2
8 2
三列 根据reyuan 作为条件 更新shjian 这一列
要求 时间以30分钟递增
update xx set shijian='' where renyuan='1' 这样 1 对应的时间只能是一样的
如果没有起始时间 怎么 实现 就如何处理2对应的时间
在 表 xx 中
id reyuan shijan
1 1 2006-5-19 14:00
2 1
3 1
4 1
5 2
6 2
7 2
8 2
三列 根据reyuan 作为条件 更新shjian 这一列
要求 时间以30分钟递增
update xx set shijian='' where renyuan='1' 这样 1 对应的时间只能是一样的
如果没有起始时间 怎么 实现 就如何处理2对应的时间
解决方案 »
- 如何在ORACLE 10G中创建带两个参数的存储过程并返回查询数据表
- 查询语句?
- 我的这句SQL语句哪错了啊?ORACLE数据库
- 请教weblogic+oracle的问题(急急急)
- 救命啊,怎么还是找不到 OracleClient 域??
- Oracle 如何用SQL求比例
- Oracle Packages
- 如何动态的定义一个游标
- 怎样编写一个oracle返回记录集的存储过程/函数?
- 急急,我编写的一个过程的状态为何总是“invalid”啊,在sqlplus里call时总是执行不了,为何?
- java下将excel中的数据批量导入到oracle 10g express edition中时经常断开连接的问题
- 如果用一个存储过程来查询 并返回多行记录 应该怎样实现?30分
insert into t1 values(1,1,sysdate);
insert into t1 values(2,1,'');
insert into t1 values(3,1,'');
insert into t1 values(4,1,'');
insert into t1 values(5,2,'');
insert into t1 values(6,2,'');
insert into t1 values(7,2,'');
insert into t1 values(8,2,'');
commit ;update t1 set shijian =
(select rid*30/(24*60) + trunc(sysdate) from
(select rownum as rid,id, shijian
from (select id, shijian from t1 where renyuan = '2' order by id))
where t1.id = id
)
where renyuan = '2' and shijian is null;取得系统时间作为初值的更新语句
看行否?
在 表 xx 中
reyuan shijan
1 2006-5-19 14:00
1
1
1
2 2006-5-22 16:00
2
2
2
根据reyuan 作为条件 更新shjian 这一列
要求 时间以30分钟递增
update xx set shijian='' where renyuan='1' 这样 1 对应的时间只能是一样的
如果没有起始时间 怎么 实现 !!??
1 2006-5-19 14:00
1 2006-5-19 14:30
1 2006-5-19 15:00
....
zhansan 2005-10-19 10:00
zhansan 2005-10-19 10:30
........
lisi 2006-2-19 7:00
lisi 2006-2-19 7:30
....类似这样的效果
SELECT c.id,c.renyuan,ROW_NUMBER()
OVER (PARTITION BY renyuan ORDER BY id) AS tid
FROM t1 c) b where a.id=b.id)结果:
1 1 2006-5-22 上午 11:08:36
2 1 2006-5-22 上午 11:38:36
3 1 2006-5-22 下午 12:08:36
4 1 2006-5-22 下午 12:38:36
5 2 2006-5-22 上午 11:08:36
6 2 2006-5-22 上午 11:38:36
7 2 2006-5-22 下午 12:08:36
8 2 2006-5-22 下午 12:38:36不知是不是你要的结果?
批量更新的可以这么实现:update t1 a set a.shijian= (
select d.tid*30/(24*60)+b.sdate
from
(select c.id, c.renyuan,nvl(c.shijian,sysdate) as sdate from
(SELECT id,renyuan, shijian ,ROW_NUMBER()OVER (PARTITION BY renyuan ORDER BY id) AS tid
FROM t1 )c where c.tid =1
)b,
(SELECT id,renyuan, shijian ,ROW_NUMBER()OVER (PARTITION BY renyuan ORDER BY id)-1 AS tid
FROM t1 )d
where d.renyuan = b.renyuan
and d.id = a.id
)
where a.shijian is null 实现的更新:
(1)当每个人的起始时间不存在的时候,从系统时间开始累计增加,即初始化时间为系统时间;
(2)每个人根据id的次序进行对时间的累计呵呵,不知道符不符合楼主的要求