union 前后select 的结果都是对的,我用了union的提示是'type mismatch in expression'
请各位帮我看一下代码(急用):
aa2:='select a.cpmc,';
aa2:=aa2+' sum(a.by_cl),sum(a.bn_cl),sum(a.sn_cl),(sum(a.bn_cl)/sum(a.sn_cl)-1)*100,';
aa2:=aa2+' sum(a.by_cz),sum(a.bn_cz),sum(a.sn_cz),(sum(a.bn_cz)/sum(a.sn_cz)-1)*100,';
aa2:=aa2+' sum(a.by_xl),sum(a.bn_xl),sum(a.sn_xl),(sum(a.bn_xl)/sum(a.sn_xl)-1)*100,';
aa2:=aa2+' sum(a.by_xe),sum(a.bn_xe),sum(a.sn_xe),(sum(a.bn_xe)/sum(a.sn_xe)-1)*100,';
aa2:=aa2+' sum(a.by_hl),sum(a.bn_hl),sum(a.sn_hl),(sum(a.bn_hl)/sum(a.sn_hl)-1)*100,';
aa2:=aa2+' sum(a.by_ccl),sum(a.bn_ccl),sum(a.sn_ccl),(sum(a.bn_ccl)/sum(a.sn_ccl)-1)*100,';
aa2:=aa2+' sum(a.by_cce),sum(a.bn_cce),sum(a.sn_cce),(sum(a.bn_cce)/sum(a.sn_cce)-1)*100,';
aa2:=aa2+' sum(a.by_qt),sum(a.bn_qt),sum(a.sn_qt),(sum(a.bn_qt)/sum(a.sn_qt)-1)*100';
aa2:=aa2+' from temp a';
aa2:=aa2+' group by a.cpmc';
aa2:=aa2+' union';
aa2:=aa2+' select '+'''总合计'''+'as b.cpmc,';
aa2:=aa2+' sum(b.by_cl),sum(b.bn_cl),sum(b.sn_cl),(sum(b.bn_cl)/sum(b.sn_cl)-1)*100,';
aa2:=aa2+' sum(b.by_cz),sum(b.bn_cz),sum(b.sn_cz),(sum(b.bn_cz)/sum(b.sn_cz)-1)*100,';
aa2:=aa2+' sum(b.by_xl),sum(b.bn_xl),sum(b.sn_xl),(sum(b.bn_xl)/sum(b.sn_xl)-1)*100,';
aa2:=aa2+' sum(b.by_xe),sum(b.bn_xe),sum(b.sn_xe),(sum(b.bn_xe)/sum(b.sn_xe)-1)*100,';
aa2:=aa2+' sum(b.by_hl),sum(b.bn_hl),sum(b.sn_hl),(sum(b.bn_hl)/sum(b.sn_hl)-1)*100,';
aa2:=aa2+' sum(b.by_ccl),sum(b.bn_ccl),sum(b.sn_ccl),(sum(b.bn_ccl)/sum(b.sn_ccl)-1)*100,';
aa2:=aa2+' sum(b.by_cce),sum(b.bn_cce),sum(b.sn_cce),(sum(b.bn_cce)/sum(b.sn_cce)-1)*100,';
aa2:=aa2+' sum(b.by_qt),sum(b.bn_qt),sum(b.sn_qt),(sum(b.bn_qt)/sum(b.sn_qt)-1)*100';
aa2:=aa2+' from temp b';
aa2:=aa2+' union';
aa2:=aa2+' select xsqd as c.cpmc,';
aa2:=aa2+' sum(c.by_cl),sum(c.bn_cl),sum(c.sn_cl),(sum(c.bn_cl)/sum(c.sn_cl)-1)*100,';
aa2:=aa2+' sum(c.by_cz),sum(c.bn_cz),sum(c.sn_cz),(sum(c.bn_cz)/sum(c.sn_cz)-1)*100,';
aa2:=aa2+' sum(c.by_xl),sum(c.bn_xl),sum(c.sn_xl),(sum(c.bn_xl)/sum(c.sn_xl)-1)*100,';
aa2:=aa2+' sum(c.by_xe),sum(c.bn_xe),sum(c.sn_xe),(sum(c.bn_xe)/sum(c.sn_xe)-1)*100,';
aa2:=aa2+' sum(c.by_hl),sum(c.bn_hl),sum(c.sn_hl),(sum(c.bn_hl)/sum(c.sn_hl)-1)*100,';
aa2:=aa2+' sum(c.by_ccl),sum(c.bn_ccl),sum(c.sn_ccl),(sum(c.bn_ccl)/sum(c.sn_ccl)-1)*100,';
aa2:=aa2+' sum(c.by_cce),sum(c.bn_cce),sum(c.sn_cce),(sum(c.bn_cce)/sum(c.sn_cce)-1)*100,';
aa2:=aa2+' sum(c.by_qt),sum(c.bn_qt),sum(c.sn_qt),(sum(c.bn_qt)/sum(c.sn_qt)-1)*100';
aa2:=aa2+' from temp c';
aa2:=aa2+' group by xsqd';
to zhaixiaobo:
dbf数据库