我现在要对Date类型的字段进行相减操作,得到相差的分钟需求The_date
2009-5-7 9:10:23
2009-5-7 8:20:36
2009-5-7 10:26:56从这个字段中选出最大的2个时间进行相减,求出其差值,单位为分钟或者秒钟
这里是2009-5-7 10:26:56  -    2009-5-7 9:10:23
谢谢大家了!

解决方案 »

  1.   

    select (a.the_date-b.the_date)/(24*60) from 
    (select the_date from (select the_Date,rownum rn from table order by the_Date desc) where rn=1) a,
    (select the_date from (select the_Date,rownum rn from table order by the_Date desc) where rn=2) b
      

  2.   

    trunc((max(the_date)-min(the_date))*1440) --分钟
    (max(the_date)-min(the_date))*86400 --秒
      

  3.   

    --获取两时间的相差分钟数
    select ceil(((To_date('2008-05-02 00:00:00' , 'yyyy-mm-dd hh24-mi-ss') - To_date('2008-04-30 23:59:59' , 'yyyy-mm-dd hh24-mi-ss'))) * 24 * 60)  相差分钟数 FROM DUAL;
    /*
    相差分钟数
    ----------
          1441
    1 row selected
    */
      

  4.   


    select ((select max(csrq) from dbzg)-(select max(csrq) from (select csrq from dbzg minus select max(csrq) from dbzg)))*1440 from dual;分钟,秒的话把1440换成24*60*60
      

  5.   


    select ((select max(the_date) from table)-(select max(the_date) from (select the_date from table minus select max(the_date) from table)))*1440 from dual;分钟,秒的话把1440换成24*60*60
      

  6.   

    --获取两时间的相差分钟数
    select ceil(((To_date('2009-5-7 10:26:56', 'yyyy-mm-dd hh24-mi-ss') - To_date('2009-5-7 9:10:23', 'yyyy-mm-dd hh24-mi-ss'))) * 24 * 60)  相差分钟数 FROM DUAL;
    /*
    相差分钟数
    ----------
          1441
    1 row selected
    */
      

  7.   

    --获取两时间的相差秒数
    select ceil((To_date('2009-5-7 10:26:56', 'yyyy-mm-dd hh24-mi-ss') - To_date('2009-5-7 9:10:23', 'yyyy-mm-dd hh24-mi-ss')) * 24 * 60 * 60) 相差秒数 FROM DUAL;
    /*
    相差秒数
    ----------
         86401
    1 row selected
    */
      

  8.   

    这个不错,不过还是有些问题,
    select the_Date,rownum rn from table order by the_Date desc  中rn并不是顺序的,而是开始时的编号
      

  9.   


    寻找排序后的需要的位置行
    select *
      from (select rownum rn, tt.*
              from (select * from tableName order by insert_time) tt)
     where rn = 3
      

  10.   

    select max(insert_time), min(insert_time) from (select *
      from (select rownum rn, tt.*
              from (select * from tableName order by insert_time) tt)
     where rn < 3)这样就可以只排序一次找出2个极值了,但是用了多次的select,不知道效率怎么样
      

  11.   

    select (a.the_date-b.the_date)/(24*60) from 
    (select the_date from (select the_Date,rownum rn from table order by the_Date desc) where rownum=1) a, 
    (select the_date from (select the_Date,rownum rn from table order by the_Date ) where rownum=1) b 
      

  12.   

    上面的错了
    select (a.the_date-b.the_date)/(24*60) from 
    (select the_date from (select the_Date from table order by the_Date desc) where rownum=1) a, 
    (select the_date from (select the_Date from table order by the_Date ) where rownum=1) b 
      

  13.   

    对 insert_time 列建索引,可以保证效率的,那样应该没事了!