合同表中,一个人员会有多条记录,其中 人员id、起始时间相同。结束时间不同。在录入数据时这些合同的状态均为1,需求是,只有结束时间最靠后的那条记录的合同状态为1;其他的为0;所需求的sql 是将结束时间比较早的那些记录的合同状态标记为0;求此sql;

解决方案 »

  1.   

    update table set htzt=0 where jssj<(select max(jssj) from table where ryid=?)
      

  2.   

    update table a set htzt=0 where jssj <(select max(jssj) from table b where b.ryid=a.ryid)
      

  3.   


    update tb set 合同状态 = 0 from tb t where 结束时间 not in (select max(结束时间) from tb where 人员 = t.人员)
      

  4.   

    update tb t set 合同状态 = 0
    where 结束时间 not in (select 结束时间 from (select max(z.结束时间) 结束时间 ,z.人员id  from tb z where z.人员id = t.人员id))
      

  5.   

    1.只更新当前人员的合同状态为0
    update contracts t set flag='0' where jssj < (select max(jssj) from das_aaa where ryid=?)
    2.更新所有人员的合同状态为0
    update contracts t set flag='0' where jssj < (select max(jssj) from das_aaa where ryid=t.ryid)
      

  6.   

    cursor c_maxsj Is
      select 人员id,max(结束时间) maxEnd
        from 合同表
       group by 人员id;
    Begin
      for t_maxsj in c_maxsj loop
        update 合同表
            set 合同状态 = 0
         where 人员id = t_maxsj.人员id
           and 结束时间 < t_maxsj.maxEnd;
      end loop;
    end;
      

  7.   

    update tb a set a.合同状态 = '0'  where a.结束时间 < (select max(b.结束时间) from tb b  where a.人员编号 = b.人员编号 and a.开始时间 = b.开始时间)