大至上这样处理就可以了的:select 名称,规格,sum(数量),avg(单价),max(日期)
from 你的表
group by 名称,规格
说明:数量求总数,单价取平均单价,日期取最后发生日期

解决方案 »

  1.   

    delcare @时间段 datetime
     select 单价,日期,count(*)
    from yourtable
    group by 名称,规格
    where (getdate()-入库日期)<=@时间段
      

  2.   

    如果想把名称和规格也查找出来,怎么办?
    select 名称,规格,单价,日期,count(*)
    from yourtable
    group by 名称,规格
    where (getdate()-入库日期)<=@时间段
    是不行的!!!
    谢谢!!!
      

  3.   

    delcare @时间段 datetime
    select 名称,规格,单价,数量,日期 from yourtable where '计数'=
     (select count(*)
     from yourtable
     group by 名称,规格
     where (getdate()-入库日期)<=@时间段)
      

  4.   

    delcare @时间段 int
    set @时间段=50  --查询50天内的记录select 名称,规格,单价,日期,sum(数量)  --求数量总和应该用sum,count是计数
    from 你的表
    where (getdate()-入库日期)<=@时间段
    group by 名称,规格,单价
      

  5.   

    delcare @时间段 int
    set @时间段=50  --查询50天内的记录select 名称,规格,avg(单价),日期,sum(数量)  --如果你只想根据名称,规格分组统计的话
    from 你的表
    where (getdate()-入库日期)<=@时间段
    group by 名称,规格
      

  6.   

    rozjcxc(邹建):
    如果只按照名称、规格分组,但是还要select出单价,sum(数量)!!
    怎么办??
      

  7.   

    可以啊,你将单价放在聚合函数中就行了,不然没办法好想.select 名称,规格,avg(单价,sum(数量)
    from 你的表
    where (getdate()-入库日期)<=@时间段
    group by 名称,规格
      

  8.   

    select *,(select sum(数量) from 物资表 where 名称=@名称 and 规格=@规格) 物资总量 from 物资表 where 名称=@名称 and 规格=@规格
      

  9.   

    select *,tem.物资总量 from 物资表,(select sum(数量) 物资总量 from 物资表 where 名称=@名称 and 规格=@规格) tem where 名称=@名称 and 规格=@规格
      

  10.   

    to pengdali(大力 V2.0) 
    好象不行啊!!