select
id, amount - (select sum(amount) as amount
from table2
where column = 'value' and table1.id = table2.id
group by table2.id) as amount
from
table1
order by
table1.id
結果は table1 からのすべての値です -amount
にないをtable2
除いて、null 値を取得します。table1.id
table2.id
null値を値にする必要があるため、null値があることを除いて、すべて問題ありませtable1.amount
ん
このようなものも試しましたが、まだ機能していません
select
id, amount - isnull((select sum(amount) as amount
from table2
where column = 'value' and table1.id = table2.id
group by table2.id), table1.amount) as amount
from
table1
order by
table1.id
それから私は取得します0.00
がtable1.id
、結果セットにnullがあるのには実際の金額の値がありますtable1.amount
必要なものの概要
table 1 values (1,12 ; 2,27 ; 3,9) table 2 values (1,9 ; 3,12) result table (1,3 ; 2,27 ; 3,-3)
結果テーブルを取得するには、table1 - テーブル 2 の値が必要です