查几点到几点,每五分钟最高报价,及最低报价
表t1,  
字段 
time  例(2012-06-25 19:00:00) 
price 
例如 21:00:00 至23:59:59
这段时间,每五分钟的最高报价及最低报价,查询后得到如下表time5       hiprice    lowprice
21:05       133          145
21:10       135          152
21:15       144          155

解决方案 »

  1.   

    select max(hiprice),min(lowprice) from time where time5 between '' and '' ;
      

  2.   

    列举了前几分钟的数据
    with t1 as
    (
         select to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss') c1,110 c2 from dual
         union all
         select to_date('2012-06-25 19:01:00','yyyy-mm-dd hh24:mi:ss') c1,120 c2 from dual
         union all
         select to_date('2012-06-25 19:06:00','yyyy-mm-dd hh24:mi:ss') c1,180 c2 from dual
         union all
         select to_date('2012-06-25 19:07:00','yyyy-mm-dd hh24:mi:ss') c1,120 c2 from dual
         union all
         select to_date('2012-06-25 19:09:00','yyyy-mm-dd hh24:mi:ss') c1,110 c2 from dual
         union all
         select to_date('2012-06-25 19:11:00','yyyy-mm-dd hh24:mi:ss') c1,90 c2 from dual
         union all
         select to_date('2012-06-25 19:11:33','yyyy-mm-dd hh24:mi:ss') c1,70 c2 from dual
         union all
         select to_date('2012-06-25 19:14:00','yyyy-mm-dd hh24:mi:ss') c1,220 c2 from dual
    )
    select n_date c1,nvl(max(c2),0) c2,nvl(min(c2),0) c3
    from 
    (
         select to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level-1)/288 m_date,
                to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level)/288 n_date
         from dual
         connect by level <= round((to_date('2012-06-26','yyyy-mm-dd')
                 -to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss'))*288,0)
    ) a left join t1 b on b.c1 between a.m_date and a.n_date
    group by n_date
    order by n_date
            c1         c2     c3
    ------------------------------------------------
    1 2012/6/25 19:05:00 120 110
    2 2012/6/25 19:10:00 180 110
    3 2012/6/25 19:15:00 220 70
    4 2012/6/25 19:20:00 0 0
    5 2012/6/25 19:25:00 0 0
    6 2012/6/25 19:30:00 0 0
    7 2012/6/25 19:35:00 0 0
    8 2012/6/25 19:40:00 0 0
    9 2012/6/25 19:45:00 0 0
    ...
      

  3.   

    只要小时分钟的话 select to_char(n_date,'hh24:mi') c1,nvl(max(c2),0) c2,nvl(min(c2),0) c3
    ...
      

  4.   

    with t1 as
    (
         select to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss') c1,110 c2 from dual
         union all
         select to_date('2012-06-25 19:01:00','yyyy-mm-dd hh24:mi:ss') c1,120 c2 from dual
         union all
         select to_date('2012-06-25 19:06:00','yyyy-mm-dd hh24:mi:ss') c1,180 c2 from dual
         union all
         select to_date('2012-06-25 19:07:00','yyyy-mm-dd hh24:mi:ss') c1,120 c2 from dual
         union all
         select to_date('2012-06-25 19:09:00','yyyy-mm-dd hh24:mi:ss') c1,110 c2 from dual
         union all
         select to_date('2012-06-25 19:11:00','yyyy-mm-dd hh24:mi:ss') c1,90 c2 from dual
         union all
         select to_date('2012-06-25 19:11:33','yyyy-mm-dd hh24:mi:ss') c1,70 c2 from dual
         union all
         select to_date('2012-06-25 19:14:00','yyyy-mm-dd hh24:mi:ss') c1,220 c2 from dual
      这都要输入吗 这样还不如目算快了
      

  5.   

    麻烦写个按我的提供的字段和举例来写的SQL ,我直接复制就能运行
      

  6.   

    上面的with 只是假设的你的表和数据  把下面sql表名字段名称改改就可以了
    2个日期是传入的参数 select n_date time5,
           nvl(max(price),0) hiprice,
           nvl(min(price),0) lowprice
    from 
    (
         select to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level-1)/288 m_date,
                to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level)/288 n_date
         from dual
         connect by level <= round((to_date('2012-06-26 00:00:00','yyyy-mm-dd hh24:mi:ss')
                 -to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss'))*288,0)
    ) a left join t1 b on b.time between a.m_date and a.n_date
    group by n_date
    order by n_date
      

  7.   

    lz发帖 没列举任何数据 那只能自己造数据了 with t1 as相当于创建一个临时表t1 然后 里面貌似时间格式还是要转换下 小时分钟
      

  8.   


    请问
    select to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level-1)/288 m_date,
                to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level)/288 n_dateconnect by level <= round((to_date('2012-06-26 00:00:00','yyyy-mm-dd hh24:mi:ss')
                 -to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss'))*288,0
    怎么解释如果 我要21:00:00 至23:59:59
    这时间段  两个小时里的  每五分钟要怎么写.
      

  9.   

    21:00:00 至23:59:59
    每五分钟下面要怎么改,能解释一下语句吗 谢谢 select to_date('2012-06-25 21:00:00<这里的时间代表什么,是起始时间吗>','yyyy-mm-dd hh24:mi:ss')+(level-1)/288 m_date,
                to_date('2012-06-25 23:59:59<这里的时间代表什么,是结束时间吗>','yyyy-mm-dd hh24:mi:ss')+(level)/288 n_date
         from dual
         connect by level <= round((to_date('2012-06-26 00:00:00<这里的时间代表什么>','yyyy-mm-dd hh24:mi:ss')
                 -to_date('2012-06-25 19:00:00'<这里的时间代表什么>,'yyyy-mm-dd hh24:mi:ss'))*288<288代表什么>,0)
    ) a left join t1 b on b.time between a.m_date and a.n_date
      

  10.   


    构建一个分钟表 2012-06-25 19:00:00是起始时间  2012-06-26 00:00:00结束时间 在程序中 只需要将时间换成参数就可以了to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level-1)/288 在起始时间基础上 以5分钟为一组循环添加  288= 1天*24小时*60分钟/5分钟 因为在oracle里面 日期直接加减是以天为单位 后面connect by ... 这是计算开始和结束时间范围内 有多少个5分钟 然后循环输出中间时间  select to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level-1)/288 m_date,
                to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss')+(level)/288 n_date
         from dual
         connect by level <= round((to_date('2012-06-26 00:00:00','yyyy-mm-dd hh24:mi:ss')
                 -to_date('2012-06-25 19:00:00','yyyy-mm-dd hh24:mi:ss'))*288,0)
      

  11.   

    中间时间混淆了  前面2个都是起始时间 只是为了构造一个5分钟的时间范围 第三个是结束时间 第四个是起始时间LZ可以直接运行上面sql 得到下面结果.               m_date             n_date
    --------------------------------------------------------
    1 2012/6/25 19:00:00 2012/6/25 19:05:00
    2 2012/6/25 19:05:00 2012/6/25 19:10:00
    3 2012/6/25 19:10:00 2012/6/25 19:15:00
    4 2012/6/25 19:15:00 2012/6/25 19:20:00
    5 2012/6/25 19:20:00 2012/6/25 19:25:00
    6 2012/6/25 19:25:00 2012/6/25 19:30:00
    7 2012/6/25 19:30:00 2012/6/25 19:35:00
    8 2012/6/25 19:35:00 2012/6/25 19:40:00
    ......
      

  12.   

    请教 再加求每5分钟的开始价 及结束价 如何改以上语句 open close