My table with user transactions in postgres looks like this:
id sender_id recipient_id amount_money --- ----------- ---------------------- ----------------- 1 1 2 60.00 2 1 2 15.00 3 2 1 35.00 The user with id number 2 has 75.00 revenues and 35.00 expenses
I would like to get a result similar to this:
[{name: 'revenues', value: 75.00}, {name:'expenses', value: 35.00}] Can such result be done in postgres sql itself? I think about array_agg function. If it is difficult, I can handle it in javascript, but I need a query that will return two values to me: revenues and expenses