Select
A.物品属性,
SUM(A.数量) As 本期,
(Select SUM(数量) From TableName Where 物品属性=A.物品属性) As 累计
From TableName
Group By A.物品属性

解决方案 »

  1.   

    --tryselect 
    物品属性,
    sum(数量) as 本期,
    (select sum(数量) from tablename where 时间<='2006/03/31' and 物品属性=a.物品属性)
    from
    tablename a
    where
    时间 between '2006/03/01' and '2006/03/31'
    group by
    物品属性
      

  2.   

    select a.物品属性,a.数量 as  本期,b.累计
    from table a 
    left join (select 物品属性,sum(数量) as  from table group by 物品属性) b 
    on a.物品属性=.物品属性
    where 时间 <=2006/03/31 and 时间 >=2006/03/01
      

  3.   

    select a.物品属性,a.数量 as  本期,b.累计
    from table a 
    left join (select 物品属性,sum(数量) as  from table group by 物品属性) b 
    on a.物品属性=.物品属性
    where 时间 <=2006/03/31 and 时间 >=2006/03/01
    group by a.物品属性
      

  4.   

    select 物品属性,sum(数量) as 累计,(select sum(数量) from tabel a where 时间 between '2006-03-01' and '2006-03-31' and 物品=a.物品 ) as 本期 
    from tabel group by 物品属性
      

  5.   

    忘了加時間范圍
    Select
    A.物品属性,
    SUM(A.数量) As 本期,
    (Select SUM(数量) From TableName Where 物品属性=A.物品属性) As 累计
    From TableName
    Where 时间 Between '2006/03/01' And '2006/03/31'
    Group By A.物品属性