现在有这么几个表:
p_purchaseplan 采购计划表
字段:billid, billkind, billstate,等
p_purchaseplandetail 采购计划明细信息表
字段: billid, goodsid,quantity(数量), price(单价)
p_purchasedetail 采购开单表 字段: billid, goodsid, quantity(数量), price(单价)
l_goods 货品信息表 主要的字段为goodsid 货品id, code 货品编码, name货品名称, unitid单位,   specs 规格
l_unit 单位表 字段 unitid单位id, name 单位名 我想实现的功能是,
联立查询出
货品编码(code), 货品名称(name), 规格, 单位,计划数量,计划金额, 完成数量,完成金额
其中,完成数量和完成金额来源于p_purchasedetail中的quantity, price.我已经实现了,查询除了完成数量和完成金额之外的信息.
select lg.code as GoodsCode, lg.name as GoodsName, lg.specs as Specs,
   lu.name as UnitName, sum(pp.quantity) as Qty, 
   sum(pp.quantity * pp.price) as Amount
   from p_purchaseplandetail pp
inner join p_purchaseplan pl on pl.billid = pp.billid
inner join l_goods lg on lg.goodsid = pp.goodsid
left join l_unit lu on lu.unitid = lg.unitid
inner join l_goodstype gt on gt.gdtypeid = lg.gdtypeid
and billstate = 1 and billkind = 1
group by lg.code, lg.name, lg.specs, lu.name;请大家看看如何把完成数量和完成金额加进去啊.

解决方案 »

  1.   

    select c.code as 货品编码,c.name as 货品名称,c.specs as 规格,d.name as 单位名,a.billkind as 计划数量,a.billstate as 计划金额,c.quantity as 完成数量,c.price as 完成金额
    from p_purchaseplan as a,p_purchaseplandetail as b,p_purchasedetail  as c,l_unit  as d
    where a.billid=b.billid and a.billid=c.billid and b.billid=c.c.billid and c.unitid=d.id
    把几个表都关联起来就可以查询出来了