Probeer dit
select cont.name, cont.total,cp.contractor_id,cp.amount_paid,wt.id
FROM
(
select name,id, sum(amount_to_be_paid) as total
from contractors group by name,id
) cont
left join
(
select contractor_id,sum(amount_paid) as amount_paid
from contractor_payments
group by contractor_id
) cp
on cont.id = cp.contractor_id
left join worktypeids as wt on cont.worktypeid_id = wt.id AND wt.project_id=2