创建视图(在不同的表上减去两个不同的列)

时间:2016-07-18 10:51:21

标签: sql oracle oracle11g

我可以创建另一个视图吗?从 total_deposit - total_loan_amount

中减去
CREATE VIEW v_total_deposit (total_deposit) as 
select sum(deposit_amount) 
from deposit;

CREATE VIEW v_total_loan (total_loan) as 
SELECT SUM(loan_amount) 
from loan;

1 个答案:

答案 0 :(得分:0)

@ moonir01 MINUS是一个集合运算符,而不是算术运算符。你必须减去两个数字:

CREATE VIEW balance
AS
   SELECT NVL((SELECT TOTAL_DEPOSIT FROM V_TOTAL_DEPOSIT),0) - NVL((SELECT TOTAL_LOAN FROM V_TOTAL_LOAN),0) AS balance
     FROM DUAL 

但你真的不需要这些观点。