select a.item,a.money,b.money,b.money-a.money
from tab_income a, tab_income b
where a.item=b.item
and a.month=to_char(add_months(to_date(b.month,'yyyymm'),1),'yyyymm')
and a.month=200504
and a.money<b.money

解决方案 »

  1.   

    select a.item,a.money,b.money,b.money-a.money
    from tab_income a, tab_income b
    where a.item=b.item
    and a.month=a.month+1
    and a.money<b.money
      

  2.   

    不好意思 写错了
    select a.item,a.money,b.money,b.money-a.money
    from tab_income a, tab_income b
    where a.item=b.item
    and a.month=b.month+1
    and a.money<b.money
      

  3.   

    使用lag分析函数:select * from(
    select item,income,month,income-lag(income,1) over (order by month) as l from 
    Tab_income order by month) where l<0