从两个表中减去派生列

时间:2015-06-11 09:45:21

标签: mysql

我有两张桌子,seet和费用,我需要选择从费用中支付的总额,并从seet中扣除它。

我尝试了下面的查询,有人可以纠正吗?

我收到此错误:

  

每个派生表必须有自己的别名

SELECT   (payable - pay) as balance 
FROM     (SELECT  sum(paid) AS pay 
           FROM   fees 
           WHERE  adm = '5685')
          UNION ALL 
          SELECT payable
           FROM   seet 
           WHERE  term = 'term1') 
         )as t1

1 个答案:

答案 0 :(得分:1)

SELECT (SELECT payable   FROM seet WHERE term = 'term1') -
       (SELECT sum(paid) FROM fees WHERE  adm = '5685') as balance