Skip to content

Instantly share code, notes, and snippets.

@oojacoboo
Created January 18, 2013 03:33
Show Gist options
  • Select an option

  • Save oojacoboo/4562139 to your computer and use it in GitHub Desktop.

Select an option

Save oojacoboo/4562139 to your computer and use it in GitHub Desktop.
SET @runningTotal:=-0.48;
SELECT
t1.*,
(@orunningTotal := @runningTotal + t1.amount) AS balance
FROM
(SELECT *
FROM `transaction` AS t
WHERE t.company_id = 1
AND t.tenant_id = 2
AND t.created_at > "2012/01/19 00:00:00"
AND t.deleted_at IS NULL
ORDER BY t.id DESC, t.created_at DESC
) AS t1
ORDER BY t1.id DESC, t1.created_at DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment