在一个表(T)内有:
  编号  属性1  收货  发货     日期
  11    红     50    0    2003-02-01  
  11    红     0     30   2003-02-03
  11    红     20    0    2003-02-05变为一个结存表:  结存日期为 2003-02-01-》2003-02-05   编号   属性1  上次结存  本次结存  期间收数 期间发数 
  11     红      0        40        70      30我用了
select(编号,属性1,isnull((select sum(收货)-sum(发货) from T where 日期<'stratdate'),0 ) as 上次结存,isnull((select sum(收货)-sum(发货) from T where 日期<'enddate'),0 ) as 本次结存,isnull((select sum(收货) from T where 日期>='stratdate' and 日期<'enddate'),0 ) as 期间收数, isnull((select sum(发货) from T where 日期>='stratdate' and 日期<'enddate'),0 ) as 期间发数 group by  编号,属性1 )但得出来的上次结存  本次结存  期间收数 期间发数都为相同数据。