数据表结构是这样的:
product_id  box_name  plan_date  in_date  out_date说明:一个工号(product_id)包括有不确定数量的配件(box_name),在入采购计划时,填写product_id/box_name/plan_date三项, in_date/out_date两项空白,然后根据实际的进仓和出仓填写后两项.现在,需要统计每月进出仓的工号数.难点在只有采购计划里的product_id对应的所有box_name都入仓了才计算一个工号入仓.
比如一个工号对应有四个配件,其中两件是上个月进仓的,另外两件是这个月入仓的,那么上个月的工号数就是0,这个月为1;

解决方案 »

  1.   

    ………………
    adoquery1.sql.add('select distinct product_id from 表');
    ………………
    while not adoquery1.eof do
    begin
      …………
      adoquery2.sql.add('select * from 表 where product_id='''+adoquery1.fields[0].asstring+''' and in_date<='''+datetostr(日期)+'''');
      adoquery3.sql.add('select * from 表 where product_id='''+adoquery1.fields[0].asstring+'''')
      if adoquery2.recordcount = adoquery3.recordcount then idcount:= idcount+1;
      …………
    end;想到那么多就写了,看看可不可以