表a:
    字段:    month     salary要求:查询每个月的该月月份、工资、上一个月工资、下一个月工资
显示格式:month   salary    lastsalary   nextsalary

解决方案 »

  1.   

    select month,salary,
    lag(salary,1,null) lastsalary,
    lead(salary,1,null)nextsalary 
    from a
      

  2.   

    如果表中月份是按顺序排列的话  上面可以了 不是的话 可以先排序再获取  或者使用add_mongths()来计算获取
      

  3.   

    select month,salary,
    lag(salary,1,null) over(order by month) lastsalary,
    lead(salary,1,null) over(order by month) nextsalary 
    from a
    这个可以有
      

  4.   


    SELECT MONTH,SALARY,LEAD(SALARY,1,SALARY)OVER(ORDER BY MONTH) LASTSALARY,
           LAG(SALARY,1,SALARY)OVER(ORDER BY MONTH) NEXTSALARY
      FROM( SELECT MONTH,SUM(SALARY) SALARY FROM T GROUP BY MONTH ) T1;
      

  5.   


    with  a
    as
    (
    select 2006 salary,6 month from dual
    union select 2007 salary,7 month from dual
    union select 2008 salary,8 month from dual
    )
    select month,salary,
    lag(salary,1,null) over(order by month) lastsalary,
    lead(salary,1,null) over(order by month) nextsalary  
    from a
      

  6.   


    错误提示:ORA-30484:丢失的此函数窗口说明!
    我试了一下   4楼的很好,不过也谢谢你!