select u.name_id,u.phone,u.username,sum(i.inmoney)-sum(o.outmoney) as balance

from  users  u  inner join  table_in i on u.name_id=i.name_id join table_out o on  u.name_id=o.name_id 
group by o.name_id,i.name_id ;