compid是项目部  item-no是材料名称 item-num 是结存库存量   请问如何求的任意月中 每中材料的库存量 每种材料的本月结存 是各个项目部最大日期的这笔材料的和求大牛帮忙

解决方案 »

  1.   

    http://hi.csdn.net/attachment/201112/15/7977584_13239126208JAh.jpg 这四个字段 除了第一个递增id外 
    我要对itemno分组  然后呢 求得每种compid 最大日期 itemnum的和   条件是时间可以查询 
    放到gridview中 两个字段列  完毕 
    比如说34这这一类分组了  统计数就是 138 
      

  2.   

    select item_no,convert(varchar(7),make_date,120),sum(item_num) from(
    select * from tb a 
    where not exists(select 1 from tb where comp_id=a.comp_id and item_no=a.item_no and convert(varchar(7),make_date,120)=convert(varchar(7),a.make_date,120) and make_date>a.make_date)
    )t group by item_no,convert(varchar(7),make_date,120)
      

  3.   

    select item_no,sum(item_num) from (
    select * from zl_zz_account t where 
    make_date in(select max(make_date) from zl_zz_account a where item_no=t.item_no and comp_id=t.comp_id  group by item_no,comp_id order by accountid desc)
    ) a 
    group by item_no  应该是这么写了  谢谢上面的朋友
      

  4.   


    select a.item-no,sum(item-num) 'item-num'
    from tab a
    inner join
    (select compid,item-no,max(Make_date) maxMake_date
    from tab
    where datepart(m,Make_date)=[指定的月]
    group by compid,item-no) b
    on a.compid=b.compid and a.item-no=b.item-no 
    and a.Make_date=b.maxMake_date
    group by a.item-no