我正在创建一个存储过程,从几个不同的表中提取聚合总和值。另外,查询很简单,使用不同的过滤器。
查询需要连接在一起,如下所示:
select distinct(bus_name), sum(act) as 'totrev', sum(budget) as 'budget rev'
from finance
where year = '2011'
and type_desc = 'rev'
group by bus_code, bus_name
order by bus_name asc
select distinct(bus_name), sum(act) as 'totalexp', sum(budget) as 'budget exp'
from finance
where year = '2011'
and type_desc = 'exp'
group by bus_code, bus_name
order by bus_name asc
select distinct(bus_name), sum(end_balance) as 'total assets'
from Balance
where year = '2011'
and type_desc = 'assets'
group by bus_code, bus_name
order by bus_name asc
select distinct(bus_name), sum(end_balance) as 'Cash'
from Balance
where year = '2011'
and type_desc = 'equity'
group by bus_code, bus_name
order by bus_name asc
select bus_code, bus_name, count(bus_code) as '#of bldgs'
from building
group by bus_code, bus_name
order by bus_name asc
我希望合并/连接所有要在一个表中查看的列。财务
表列 = bus_code、bus_name、# of bldgs、tot_rev、budget_rev、totalexp、budget exp、总资产、现金