库存表:编号,名称
入库表:日期,编号,入库数量
我想按名称汇总在某段时间范围内的入库数量

解决方案 »

  1.   

    select sum(入库表.入库数量) as s入库数量,max(入库表.编号),库存表.名称 into #temptable from 入库表 inner join 库存表 on 入库表.编号 = 库存表.编号 where 入库表.日期 between '2000-1-1' and '2005-1-1' group by 库存表.名称
    select * from #temptable
    Drop Table #temptable  
      

  2.   

    select a.名称 sum(b.入库数量) as 数量
    from 库存表 a,入库表 b
    where a.编号=b.编号 and b.日期>=开始日期 and b.日期<=结束日期
      

  3.   

    http://community.csdn.net/Expert/topic/3903/3903036.xml?temp=.6081049