いくつかの異なるテーブルから集計合計値を取得するストアド プロシージャを作成しています。これとは別に、クエリはさまざまなフィルターで単純化されています。
クエリは結合する必要があり、次のようになります。
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
基本的に1つのテーブルに表示されるすべての列をマージ/結合しようとしています。finance_table
列 = bus_code、bus_name、ビル数、tot_rev、budget_rev、totalexp、budget exp、総資産、現金