Created
July 3, 2012 05:48
-
-
Save oojacoboo/3037942 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT t.`id`, t.`reference_id`, t.`tenant_id`, t.`amount`, | |
| ( | |
| SELECT SUM(t.`amount`) | |
| FROM `transaction` t | |
| ) AS total | |
| FROM `transaction` t | |
| WHERE total > 0 | |
| GROUP BY t.`reference_id`; |
Author
Author
SELECT t.id, t.reference_id, t.tenant_id, t.amount, SUM(t.amount) total
FROM transaction t
GROUP BY t.reference_id
HAVING total > 0
Author
SELECT t.id, t.reference_id, t.tenant_id, t.amount,
(
SELECT SUM(t.amount)
FROM transaction t
WHERE t.deleted_at IS NOT NULL
) AS total
FROM transaction t
GROUP BY t.reference_id
HAVING total > 0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SELECT t.
id, t.reference_id, t.tenant_id, t.amountFROM
transactiontWHERE total =
(
SELECT total
FROM (
SELECT SUM(t.
amount) as totalFROM
transactionst) t
GROUP BY t.
reference_idWHERE total > 0 ) t