查询问题
表hygl hyh mgz (合约管理)
表caiwu id hyh total c_date(施工队获得的财务款)
表d_material_out id hyh total out_date(施工队耗用材料款)
表nb_jl id hyh total jl_date (内部计量,确定施工队的总计应得收入)
查询的结果格式为
合约号 施工队伍 本期应支付 本期实际支付 至上期欠付 累计20%未支付
hyh mgz
耗用材料款 累计欠付金额
说明:本期应支付是: 内部计量*80%
本期实际支付 :施工队获得的财务款
现在要统计出:1.某年某月 2.连续的一段时间(以月为单位)
表hygl hyh mgz (合约管理)
表caiwu id hyh total c_date(施工队获得的财务款)
表d_material_out id hyh total out_date(施工队耗用材料款)
表nb_jl id hyh total jl_date (内部计量,确定施工队的总计应得收入)
查询的结果格式为
合约号 施工队伍 本期应支付 本期实际支付 至上期欠付 累计20%未支付
hyh mgz
耗用材料款 累计欠付金额
说明:本期应支付是: 内部计量*80%
本期实际支付 :施工队获得的财务款
现在要统计出:1.某年某月 2.连续的一段时间(以月为单位)
close;
sql.Clear;
sql.Add('select hygl.hyh,hygl.mgz,');
sql.Add(' bqyzf=0.8*(select sum(total) from nb_jl');
sql.Add(' where hygl.hyh=nb_jl.hyh and year(jl_date)='+#39+Edit2.Text+#39'');
sql.Add('and month(jl_date)='+#39+Combobox2.Text+#39'),');
sql.Add(' bqsjzf=(select sum(caiwu.total) from caiwu ');
sql.Add(' where hygl.hyh=caiwu.hyh');
sql.Add(' and year(caiwu.c_date)='+#39+Edit2.Text+#39'');
sql.Add('and month(caiwu.c_date)='+#39+Combobox2.Text+#39'),');
sql.Add(' zsqqf=(0.8*(select sum(nb_jl.total) from nb_jl');
sql.Add(' where hygl.hyh=nb_jl.hyh and (year(nb_jl.jl_date)<'+#39+Edit2.Text+#39'');
sql.Add('or month(nb_jl.jl_date)<'+#39+Combobox2.Text+#39' and year(nb_jl.jl_date)='+#39+Edit2.Text+#39'))');
sql.Add('-(select sum(caiwu.total) from caiwu');
sql.Add('where hygl.hyh=caiwu.hyh');
sql.Add('and (year(caiwu.c_date)<'+#39+Edit2.Text+#39' or ');
sql.Add(' year(caiwu.c_date)='+#39+Edit2.Text+#39'');
sql.Add('and month(caiwu.c_date)<'+#39+Combobox2.Text+#39'))),');
sql.Add('ljbfwzf=0.2*(select sum(nb_jl.total) from nb_jl');
sql.Add('where hygl.hyh=nb_jl.hyh');
sql.Add('and (year(nb_jl.jl_date)<'+#39+Edit2.Text+#39'');
sql.Add('or year(nb_jl.jl_date)='+#39+Edit2.Text+#39'');
sql.Add('and month(nb_jl.jl_date)<='+#39+Combobox2.Text+#39')),');
sql.Add('ljclk=(select sum(d_material_out.total) from d_material_out');
sql.Add('where hygl.hyh=d_material_out.hyh');
sql.Add('and (year(d_material_out.out_date)<'+Edit2.Text+'');
sql.Add('or year(d_material_out.out_date)='+#39+Edit2.Text+#39'');
sql.Add('and month(d_material_out.out_date)<='+#39+Combobox2.Text+#39'))');
sql.Add('from hygl');
sql.Add('group by hygl.hyh,hygl.mgz');
prepared;
open;
sql.Add('from hygl');
sql.Add('group by hygl.hyh,hygl.mgz');
prepared; //请楼主给解释这句是什么意思
open;
sql.Add('group by hygl.hyh,hygl.mgz');
//是按照hygl表中的hyh(合约号),mgz(施工队伍)进行分组,不包含在聚合函数里面的字段都要分组的
prepared//我用的是adoquery
open;//打开数据集