下面我有以下SQL查詢:SQL查詢:加入工會的結果,所有查詢
select SUM(Amount) Amount
from
(
select Amount from IncomeSource1
union all
select Amount from IncomeSource2
) inc
現在我需要過濾此表的基礎上的一些類型,它是在不同的表中的結果。比方說,連接會是這樣:
select Amount
from IncomeSource1 ic1
left join IncomeType it on it.id = ic1.id
where it.IncomeType = 1
我想低於此,但沒有運氣,我仍然得到大量的全部總和。
select Id, SUM(Amount) Amount
from
(
select Id, Amount from IncomeSource1
union all
select Id, Amount from IncomeSource2
) inc
left join IncomeType it on it.id = inc.id and it.IncomeType = 1
我該如何做到這一點?