select a.id,a.month nmonth,a.qty nqty,a.cost ncost,
       lag(a.month) over(partition by a.id order by a.month) lmonth,
       lag(a.qty) over(partition by a.id order by a.month) lqty,
       lag(a.cost) over(partition by a.id order by a.month) lcost,
       b.RECQTY,LINECOST LINECOST2,c.USEQTY,LINECOST LINECOST1
from a,b,c
where a.id = b.id(+) and a.month = b.month(+)
and   a.id = c.id(+) and a.month = c.month(+)
ORDER BY a.MONTH

解决方案 »

  1.   

    谢谢duanzilin(寻) 的解答,问题解决了
    但是有点小疑问请解释一下
    我的a表的数据是在每个月最后一天的23:00启动一个job将其他表的数据插入进来的
    现在我用duanzilin(寻)的方法把a,b,c表的一些创建成一个试图
    这样,在每个月最后一天,表中有数据插入时,会不会给服务器造成很大的负担?
    简单的说就是视图里的数据是什么时候被更新的,是在对视图做查询的时候还是被创建视图的表中数据插入或更新的时候?
    谢谢。
      

  2.   

    UP,很想知道OVER函數是做什麼用的?