现有表monitor_indexforecast,
各字段分别是: TYPE  ITIME  FCDATE  FCHH  VTI  CITYNUMBER  DATASOURCE  INDEXFILENAME  ERRSTATION  
原来做法是先:select dinstinct(type||vti) from monitor_indexforecast,这样将得到84条记录
将获取到的type||vti分别保存在两个数组中,然后再执行:select * from monitor_indexforecast where itime=(select max(itime) from monitor_indexforecast where type like '%type_array[i]%' and vti like '%vti_array[i]%')这样相当于要先执行一次查询,再执行84条查询来获取想要的记录,有没有一条语句获取到想要的记录集达到这85条SQL的效果?

解决方案 »

  1.   

    select * from monitor_indexforecast t,
       (select type||vti tv, max(itime) mt from monitor_indexforecast group by type||vti) t1 
        where t.type||t.vti=t1.tv and t.itime=t1.mt 
      

  2.   

    select t.* from monitor_indexforecast t, 
      (select type||vti tv, max(itime) mt from monitor_indexforecast group by type||vti) t1 
        where t.type||t.vti=t1.tv and t.itime=t1.mt 
      

  3.   


    --不用数组,试一下:select dinstinct(type || vti)
      from monitor_indexforecast
    union
    select a.type || a.vti max_t_v
      from monitor_indexforecast a,
           (select max(itime) mi from monitor_indexforecast) b
     where a.itime = b.mi;
      

  4.   


    select t.* from monitor_indexforecast t
    (select type||vti tv,itime mt,row_number() over(order by itime desc) rn from monitor_indexforecast) t1
    where t.type||t.vti=t1.tv and t.itime=t1.mt and t1.rn=1
      

  5.   


    将上面的再改一下
    select t.* from monitor_indexforecast t
    (select type||vti tv,itime mt,row_number() over(partion by type||vti order by itime desc) rn from monitor_indexforecast) t1
    where t.type||t.vti=t1.tv and t.itime=t1.mt and t1.rn=1
      

  6.   

    试用了wfqqwer5213 的第二个语句,确实得到了我想要的结果。同时感谢大家的参予和支持,让我这么快就得到圆满的答案!