1.货品信息表T_Goods:GoodCode,GoodName,Type,Unit,Price,Number,Money
  进货单:T_InGoods:BillCode(单号),InGoodsDate,GoodName,Price,
                    Number,Money;
  我想对进货按货品名称对数量和金额进行汇总,达成下面这样的效果:
  GoodCode1  GoodName1 Type Unit Price Number Money
  GoodCode2  GoodName2 Type Unit Price Number Money 
  GoodCode3  GoodName3 Type Unit Price Number Money
     .         
     .
     .
  这里的Number和Money 都是合计后的数据,这样的SQL语句怎么写?2.我的进货表只能存放最后一条记录,每次输入一条新记录的时候系统自动把以前的记录
  给清除掉了,这是怎么回事?我代码里没有Delete from T_InGoos.3.删除主从表的数据问题:在按钮Delete触发时间里写
  if MessageBox(Self.Handle, '您确定要删除该记录吗?','警告',MB_YesNo or MB_ICONInformation)=IDYes then
  begin
    Frm_Data.Qry_Bill.Delete;//删除主表信息
    Frm_Data.Qry_BillDetail.Delete;//删除从表信息
  end;
 但总是报错,请问问题出在哪里?

解决方案 »

  1.   

    1、没详细看,汇总通常用group by语法
    2、应是你代码的问题,仔细跟踪调试
    3、应该先删除从表吧?
      

  2.   

    1、用group by
    select GoodCode,GoodName,Type,Unit,Price,sum(Number),sum(Money) from ...
    group by  GoodCode,GoodName,Type,Unit,Price
    2、应是你代码的问题,仔细跟踪调试
    3、应该先删除从表
      

  3.   

    Delete:
    Deletes the active record and positions the dataset on the next record.
      

  4.   

    1.
    select a.GoodCode, a.GoodName, A.Type, A.Unit, A.Price, Sum(B.Number) as Number, sum(B.Money) as Money
    from T_Goods a, T_InGoods b 
    where a.GoodCode = b.GoodCode
    group by a.GoodCode, a.GoodName, A.Type, A.Unit, A.Price3. 先删除从表,再删除主表
      if MessageBox(Self.Handle, '您确定要删除该记录吗?','警告',MB_YesNo or MB_ICONInformation)=IDYes then
      begin
        Frm_Data.Qry_BillDetail.Delete;//删除从表信息
        Frm_Data.Qry_Bill.Delete;//删除主表信息
      end;