select a.数量-b.数量 from table1 a ,table1 b  where a.类别=b.类别 and a.数量>b.数量

解决方案 »

  1.   

    select x.数量-y.数量 from table x,table y 
    where to_char(x.日期,'yyyymmdd')=to_char(y.日期,'yyyymmdd')+1
     and x.类别=y.类别
      

  2.   

    select a.数量-b.数量 
       from (select 日期,数量,类别 from table ) a,
            (select 日期-1,数量,类别 from table ) b
       where a.日期=b.日期 And a.类别=b.类别或者是,两个的效率不同,试试select a.数量-b.数量 
       from (select 日期,数量,类别 from table ) a,
            (select 日期,数量,类别 from table ) b
       where a.日期+1=b.日期 And a.类别=b.类别
      

  3.   

    错了!
    select a.数量-b.数量 
       from  table  a,
             table  b
       where a.日期+1=b.日期 And a.类别=b.类别上边人的和我这个一样,我刚才没看明白,抱歉!
      

  4.   

    又错了!
    select a.数量-b.数量 
       from  table  a,
             table  b
       where a.日期=b.日期+1 And a.类别=b.类别
      

  5.   

    不是太明白楼主意思。
    看是否这样:
    select lead(数量,1,null) over(partition by 类别 order by 日期)-数量 from table_name
      

  6.   

    select x.数量-y.数量 from table x,table y 
    where to_char(x.日期,'yyyymmdd')="2003-01-02" and to_char(x.日期,'yyyymmdd')="2003-01-01"
     and x.类别=y.类别
      

  7.   

    如果是想根据这个原理做group by 呢?
    那应该怎么做呢?首先时间条件就不正确了,需要从新考虑一下where 子句了