From postgresql:
select client_id, sum(net_amount) from purchases left join accounts on accounts.id= contracts.account_id where purchase_date <= \'2020-05-08\'