if OBJECT_ID('tb') is not null drop table tb
go
create table tb(Date1 datetime, ctype varchar(10),qnt float,pri float)
insert tb
select '2009-1-1', '库存',  100,  8 union all 
select '2009-1-3', '出货',  20,  12 union all 
select '2009-1-5', '进货',  50,  10 
我的问题单纯用上面的价格算成本价,不考虑别的因素主要问题是要不要按时间来操作
就是说先出货的要不要先扣掉加权平均法是什么意思

解决方案 »

  1.   

    qnt 是数量
    Pri 是价格
      

  2.   

    select sum(qnt*pri) from tb where ctype  in ('库存','进货')
     如果有许多产品,按产品分组就可以得到成本了,出库的时候(销售)就是收入了
      

  3.   


    进货的价格不是成本价,select date1,avg(pri) pri from tb  where ctype='进货'
          group by date1
      

  4.   

    我要的就是三楼说的
    if OBJECT_ID('tb') is not null drop table tb
    go
    create table tb(Date1 datetime, ctype varchar(10),qnt float,pri float)
    insert tb
    select '2009-1-1', '进货',  100,  8 union all 
    select '2009-1-3', '出货',  20,  12 union all 
    select '2009-1-5', '进货',  50,  10 union all 
    select '2009-1-7', '出货',  30,  15 union all 
    select '2009-1-8', '进货',  10,  8 
      

  5.   

    2出货以后的成本价是c2=(100*8-20*8)/(100-20)
    3进货以后的成本价是c3=(80*c2+50*10)/(80+50)
    4出货以后的成本价是c4=(130*c3-30*c3)/(130-30)
    .
    .
    .