SELECT distinct a.购房人,a.房间号,(a.总房价 -
(SELECT SUM( b.已收款金额 )
FROM table1 a, table2 b
WHERE a.房间号 = b.房间号
))
FROM table1 a,table2 b where
a.房间号 = b.房间号
或者按楼主的方法
SELECT distinct a.购房人,a.房间号,(a.总房价 - (
SELECT SUM( b.已收款金额 )
FROM table1 a, table2 b
WHERE a.房间号 = b.房间号
) )
FROM table1 a
LEFT JOIN table2 b ON
a.房间号 = b.房间号
不能用group by 语句,不过还是不太好
楼主写的不对,首先b.SUM(已收款金额) 不能这么写,sum(b.已收款金额)还行。这种left join groupby 也不能这么用。
在Oracle里面加减乘除是可以直接用+-*/的,也就是说"a.总房价"后面可以直接跟运算符。