查几点到几点,每五分钟最高报价,及最低报价
表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
表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
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
...
...
(
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
这都要输入吗 这样还不如目算快了
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
请问
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
这时间段 两个小时里的 每五分钟要怎么写.
每五分钟下面要怎么改,能解释一下语句吗 谢谢 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
构建一个分钟表 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)
--------------------------------------------------------
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
......