有一表
datetime               num1 num2
2008-01-01 01:00:01    15    12
2008-01-01 01:00:02    5     4 
2008-01-01 01:00:03    4     3    
'
'
'  
2008-01-01 01:34:01    2     2
2008-01-01 01:35:01    20    11我想查询出 当NUM1<=5 且 NUM2<=5 时间超过30分钟的 情况 开始时间及结束时间询程序思路?

解决方案 »

  1.   


    select datetime 
    from table_A
    where NUM1 <=5 
          and NUM2 <=5
          and (trunc(to_date('2008-01-01 01:06:01','yyyy-MM-dd hh24:mi:ss'),'mi')
              -
              trunc(to_date('2008-01-01 01:06:01','yyyy-MM-dd hh24:mi:ss'),'hh24'))*24*60 > 30;
    你看看是不是這樣
      

  2.   


    select datetime 
    from table_A
    where NUM1 <=5 
          and NUM2 <=5
          and (trunc(to_date(datetime,'yyyy-MM-dd hh24:mi:ss'),'mi')
              -
            trunc(to_date(datetime,'yyyy-MM-dd hh24:mi:ss'),'hh24'))*24*60 > 30;
    發錯了  把試驗的數據發上去了 ~~
      

  3.   

    select max(datetime) as endtime,min(datetime) as begintime 
    from table
    where 
    num1<=5 
    and num2<=5 
    and (select max(datetime) from table)-(select min(datetime) from table0>30这样应该可以查出这个表中的开始和结束时间差30分钟,时间超过30分钟是什么意思??能说明白点不
      

  4.   

    我原以为Date类中有计时的方法呢 查了下没找到,期待高手。
      

  5.   

    1、查询出第一条NUM1 <=5 且 NUM2 <=5的记录
    2、将游标下移,再继续查询下一条符合NUM1 <=5 且 NUM2 <=5的记录
    3、比较两条记录的时间,如果时间没超过30分钟, 继续去下一条
      

  6.   

    顶楼上的,
    不过时间超过30分钟的话,就直接MM<30好了
      

  7.   

    http://topic.csdn.net/u/20071220/11/8f99f6be-bc64-4f89-8f1d-585d3e814799.html参照一下吧
      

  8.   


    明白了一下,又迷糊了你这第一次,第二次是指什么呀
    第一次复合情况的 2008-01-01 01:00:02    2008-01-01 01:34:01 此时若表中多了一条记录 datetime列为 2008-01-01 01:35:01 
    第二次复合情况为 2008-01-01 01:00:02    2008-01-01 01:35:01 ??此时若表中多了一条记录 datetime列为 2008-02-01 01:35:01 
    第二次复合情况为 2008-01-01 01:00:02    2008-02-01 01:35:01 ??
      

  9.   

    有一表 
    datetime              num1 num2 
    2008-01-01 01:00:01    15    12 
    2008-01-01 01:00:02    5    4 
    2008-01-01 01:00:03    4    3    


    '  
    2008-01-01 01:34:01    2    2 
    2008-01-01 01:35:01    20    11 
    2008-01-01 01:36:00    5    4


    '
    2008-01-01 02:10:00    4    3
    2008-01-01 02:11:01    20    11 我想要的结果
    1  2008-01-01 01:00:02   2008-01-01 01:34:01
    2  2008-01-01 01:36:00   2008-01-01 02:10:00 
      

  10.   

    select datetime 
    from table_A
    where NUM1 <=5 
          and NUM2 <=5
          and (trunc(to_date(datetime,'yyyy-MM-dd hh24:mi:ss'),'mi')
              -
            trunc(to_date(datetime,'yyyy-MM-dd hh24:mi:ss'),'hh24'))*24*60 > 30;正解!
      

  11.   

    select datetime 
    from table_A 
    where NUM1 <=5 
          and NUM2 <=5 
          and (trunc(to_date(datetime,'yyyy-MM-dd hh24:mi:ss'),'mi') 
              - 
            trunc(to_date(datetime,'yyyy-MM-dd hh24:mi:ss'),'hh24'))*24*60 > 30; 就这样做的
      

  12.   

    这个需要用Sql直接查出来不太容易.
    我的思路:
    1.先查询整张表,然后按照时间排序."select * from datetime_table order by datetime"
    2.在循环中通过条件判断,把满足条件的放入到List中.循环判断中,是当不满足条件时,把记录的最后满足的记录放到list中.