如何根据付款金额和收款金额获得帐户余额呢?
SELECT sum(jyje) as _AttValue from jymx where fkrzh= '001 '
这个可以获得所有的账号是001的付款金额
SELECT sum(jyje) as _AttValue from jymx where skrzh= '001 '
这个可以获得所有的账号是001的收款金额
我想获得余额,就是所有的收款金额减去所有的付款金额,该怎么写sql呢?
------解决方案--------------------SELECT
(SELECT sum(jyje) as _AttValue from jymx where fkrzh= '001 ')-
(SELECT sum(jyje) as _AttValue from jymx where skrzh= '001 ')
OR
SELECT A.fkrzh,SUM(jyje)-sum(jyje)
from jymx A INNER JOIN jymx B
ON A.fkrzh=B.skrzh
GROUP BY A.fkrzh
------解决方案--------------------SELECT
A.fkrzh,
SUM(B.jyje)-sum(A.jyje) as 差额
from jymx A
INNER JOIN jymx B ON A.fkrzh=B.skrzh
where A.fkrzh= '001 '
GROUP BY A.fkrzh