I need to make an appointment that returns the employee's current balance.
Being that in my modeling I separate the debts and credits of the employee by the fields type 1
for credits and 2
for debits. My query is not bringing the total value grouped by employee, it returns only the subtraction of the first record found.
SELECT
(SELECT SUM(valor) from 'conta_corrente_funcionario' c WHERE 'tipo' = '1') -
(SELECT SUM(valor) from 'conta_corrente_funcionario' d WHERE 'tipo' = '2') as total
FROM conta_corrente_funcionario' totais
group by
totais.idFuncionario