Open tomsmith8 opened 5 months ago
Stub: Monitoring where withdraw > deposits balance
The SQL command to find workspaces with balances different than the sum of workspace transactions:
select ph.workspace_uuid, w.name, SUM(case when payment_type = 'withdraw' THEN amount -1 ELSE amount END) as amount, bb.total_budget, MAX(ph.updated) as last_transaction, MIN(ph.updated) as first_transaction from payment_histories as ph inner join workspaces as w on w.uuid = ph.workspace_uuid inner join bounty_budgets as bb on bb.workspace_uuid = ph.workspace_uuid WHERE status = true GROUP BY ph.workspace_uuid, w.name, bb.total_budget HAVING SUM(case when payment_type = 'withdraw' THEN amount -1 ELSE amount END) <> total_budget ORDER by amount DESC
Task
SQL qeury: