SHARE
TWEET

Untitled

a guest Dec 12th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2.   test_table.arrangement_id,
  3.   credit.credit_amount_sum AS credit_sum,
  4.   debit.debit_amount_sum   AS debit_sum
  5. FROM test_table
  6.   LEFT JOIN (
  7.               SELECT
  8.                 arrangement_id,
  9.                 SUM(amount) AS credit_amount_sum
  10.               FROM test_table
  11.               WHERE credit_debit_indicatintor = 'credit'
  12.               GROUP BY arrangement_id
  13.             ) credit ON credit.arrangement_id = test_table.arrangement_id
  14.   LEFT JOIN (
  15.               SELECT
  16.                 arrangement_id,
  17.                 SUM(amount) AS debit_amount_sum
  18.               FROM test_table
  19.               WHERE credit_debit_indicatintor = 'debit'
  20.               GROUP BY arrangement_id
  21.             ) debit ON debit.arrangement_id = test_table.arrangement_id
  22. WHERE credit_amount_sum > debit_amount_sum
  23. GROUP BY test_table.arrangement_id
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top