举个例子:
这是中午写的一段sql的查询语句
select c.entnature_name,c.entnature_firname,sum(a.A01),sum(a.A02),sum(a.A03),sum(a.A04),
sum((a.A03-a.A07)/a.A07)*100 AS B1,sum((a.A04-a.A08)/a.A08)*100 AS B2,
(select sum(a01) from td_enterprise_impexp_stat)as b3,sum(a.a03)/(select sum(a01) from td_enterprise_impexp_stat)*100 as b4,
(select sum(a02) from td_enterprise_impexp_stat)as b5,sum(a.a04)/(select sum(a02) from td_enterprise_impexp_stat)*100 as b6
from tb_common_enterprise_nature c left join tb_enterprise_info b on c.entnature_code=b.entnature_code left join td_enterprise_impexp_stat a
on b.enterprise_code=a.enterprise_code where ymonth='${pymonth}' ;
在第五行可以看到(select sum(a02) from td_enterprise_impexp_stat)as b5在句内选择语句外的表进行求和查询,直接用select调用就可以了!!!!