select * from (select *,iif(实际>预算,"大于1",iif(实际<预算*0.2,"小于20%","0")) as 分段 from (select 下属分公司,费用类型,费用明细一级科目,费用明细二级科目,sum(预算) as 预算,0 as 实际 from [管理费用年预算$] group by 下属分公司,费用类型,费用明细一级科目,费用明细二级科目) union all select 下属分公司,费用类型,费用明细一级科目,费用明细二级科目,0 as 预算,sum(实际) as 实际 from [管理费用数据库$] group by 下属分公司,费用类型,费用明细一级科目,费用明细二级科目))
更正为:select * from (select *,iif(实际>预算,"大于1",iif(实际<预算*0.2,"小于20%","0")) as 分段 from (select 下属分公司,费用类型,费用明细一级科目,费用明细二级科目,sum(预算) as 预算,0 as 实际 from [管理费用年预算$] group by 下属分公司,费用类型,费用明细一级科目,费用明细二级科目 union all select 下属分公司,费用类型,费用明细一级科目,费用明细二级科目,0 as 预算,sum(实际) as 实际 from [管理费用数据库$] group by 下属分公司,费用类型,费用明细一级科目,费用明细二级科目))
错误地方:
UNION ALL前面的")"是多余的,另外,其实不用再SELECT * FROM 表的. 直接改成下面就可以了.
select *,iif(实际>预算,"大于1",iif(实际<预算*0.2,"小于20%","0")) as 分段 from (select 下属分公司,费用类型,费用明细一级科目,费用明细二级科目,sum(预算) as 预算,0 as 实际 from [管理费用年预算$] group by 下属分公司,费用类型,费用明细一级科目,费用明细二级科目 union all select 下属分公司,费用类型,费用明细一级科目,费用明细二级科目,0 as 预算,sum(实际) as 实际 from [管理费用数据库$] group by 下属分公司,费用类型,费用明细一级科目,费用明细二级科目) |