create or replace view hour_max as
select time,d_num,m_no,name,ins,out_f from mv,
(select
max(in_f) ins
from mv)
where
in_f!=0 and out_f!=0 and
in_f=ins
order by name,time
你看可以吗?
你能否将你要实现什么,贴上来

解决方案 »

  1.   

    我上面的语句思路是在一个表或者视图里
    把一个对象在一小时内的最
    大值给找出来。
    时间格式:2005-02-22 13:45:00
    所以用到了substr(time,1,13)
    如:time                    name      value
    2005-02-22 13:00:00     a           0
    2005-02-22 13:15:00     a           9
    2005-02-22 13:30:00     a           7
    2005-02-22 13:45:00     a           4
    2005-02-22 13:00:00     b          5
    2005-02-22 13:15:00     b           3
    2005-02-22 13:30:00     b          7
    2005-02-22 13:45:00     b           4
      

  2.   

    看一下语句的执行计划!
    select time,d_num,m_no,name,ins,out_f from mv,
    (select
    substr(time,1,13) c_time,n_name name,max(in_f) ins
    from mv
    group by name,substr(time,1,13))
    where
    in_f!=0 and out_f!=0 and
    name=n_name and in_f=ins and substr(time,1,13)=c_time 
    order by name,time
      

  3.   

    substr(time,1,13)=c_time
    这个条件不会使用time上的索引既然只要匹配前13个字符,可以考虑用like ‘xxx%’,这样就可以使用time上的索引了