求一条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对应的时间

解决方案 »

  1.   

    create table t1 (id varchar2(2),renyuan varchar2(2),shijian date);
    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;取得系统时间作为初值的更新语句
      

  2.   

    update t1 set shijian =(select shijian-(interval'1'hour/2) from t1 where renyuan='1') where renyuan='2'
    看行否?
      

  3.   

    求一条SQL语句
    在 表 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 对应的时间只能是一样的
    如果没有起始时间 怎么 实现   !!??
      

  4.   

    我想 得到 renyuan          shijian
    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
    ....类似这样的效果
      

  5.   

    借用了xiaoxiao1984建的表,xiaoxiao1984的语句在批量处理的时候可能是个问题这里以系统时间做为开始时间update t1 a set a.shijian=(select b.tid*30/(24*60)+sysdate shijian from (
    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不知是不是你要的结果?
      

  6.   

    要是有起始时间,上面语句sysdate那可以判断,稍微改一下
      

  7.   

    to Fancy2004(Fancy2004) : 呵呵,当时写的就不是批量更新的呢,只是针对某个人员的更新
    批量更新的可以这么实现: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的次序进行对时间的累计呵呵,不知道符不符合楼主的要求