if have 2 tables:
TABLE "deposit"
card | amount
------------
2 | 123.43
2 | 56.45
3 | 21.19
+
TABLE "payment"
card | price | status
-----------
2 | 10.59 | finish
2 | 10.59 | pending
10 | 12.40 | finish
2 | 10.59 | finish
What i looking for is the remaining deposit for a card-id.
Example for card 2: 123.43 + 56.45 - 10.59 - 10.59 (only status = finish)
or: SUM(deposit for card id = 2) - SUM(payment for card id = 2 and status = finish)
I tried the following mysql-select:
SELECT(
IFNULL(SUM(deposit.amount),0) - IFNULL(SUM(payment.price),0)
) AS remaing_deposit
FROM deposit, payment
WHERE deposit.card = '2'
OR (
payment.card = '2' AND payment.status = 'finish'
)
But i get complete wrong Numbers.
Can anybody help me?