Advertisement
gahcep

TestSQL1

Jun 5th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.50 KB | None | 0 0
  1. SELECT p.client_id AS CLIENT, SUM(p.sum)-_inner.Issuance AS SALDO
  2.   FROM processing AS p
  3. INNER JOIN
  4.   (
  5.     SELECT client_id, SUM(sum) AS Issuance FROM processing
  6.         WHERE operation_id =
  7.                 (
  8.                   SELECT id FROM operation WHERE name = 'issuance'
  9.                 )
  10.         GROUP BY client_id, operation_id
  11.   )
  12.   AS _inner
  13. ON _inner.client_id = p.client_id
  14.   WHERE p.operation_id =
  15.     (
  16.       SELECT id FROM operation WHERE name = 'payment'
  17.     )
  18.   GROUP BY p.client_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement