I have a transactions table which contains a category (category_id), an amount (amount) and a flag (managed) which can be true or false.
I would like to display a list of all categories with the total amounts of managed and not managed transactions, e.g.
Category | managed_transactions | unmanaged_transactions
Cat 1 | 124000 | 54000
Cat 2 | 4000 | 0
Cat 3 | 854000 | 1000000
Is there a way to do something like
Select category_id,
sum(amount) if (managed is true) as managed_transactions,
sum(amount) if (managed is false) as unmanaged_transactions
from transactions
I’m obviously stuck on the if managed is true part…
Enjoy!