SQL语句:update WebTimer set endUserID=getdate() where endUserID is null and datediff(hh,beginUserid,getdate())>2

解决方案 »

  1.   

    update WebTimer set endUserID = sysdate where endUserID is null and 
    to_date(to_char(sysdate,'yyyy-mm-dd hh24'),'yyyy-mm-dd hh24') - to_date(to_char(beginUserid,'yyyy-mm-dd hh24'),'yyyy-mm-dd hh24') > 2
      

  2.   

    update WebTimer set endUserID=sysdate where endUserID is null and (sysdate - beginUserid) < 2 / 24
      

  3.   

    不好意思,上一个写错啦
    update WebTimer set endUserID = sysdate where endUserID is null and
    (to_date(to_char(sysdate,'yyyy-mm-dd hh24'),'yyyy-mm-dd hh24') - to_date(to_char(beginUserid,'yyyy-mm-dd hh24'),'yyyy-mm-dd hh24'))*24 > 2
      

  4.   

    update WebTimer 
       set endUserID = sysdate 
     where endUserID is null 
       and beginUserid < sysdate - 2/24where 条件左边尽量少用函数以保证索引的正确使用
      

  5.   

    谢谢xiaoxiao1984(笨猫儿^_^). smilingchen(钝哥)