Created
October 3, 2021 15:20
-
-
Save devmnj/69be4a0a939f91a480148caa2c2f2e31 to your computer and use it in GitHub Desktop.
SQL Case... when example
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 invoice , | |
case | |
when isnull(sum(tr.cramount),0)>isnull(sum(tr.dramount),0) then isnull(sum(tr.cramount),0)-isnull(sum(tr.dramount),0) | |
else 0 | |
end as cr, | |
case | |
when isnull(sum(tr.dramount),0)>isnull(sum(tr.cramount),0) then isnull(sum(tr.dramount),0)-isnull(sum(tr.cramount),0) | |
else 0 | |
end as dr | |
FROM transactions AS tr INNER JOIN accounts AS ac ON tr.DRID | |
= ac.id inner join accounts ac1 on tr.crid=ac1.id group by invoice,tr.drid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment