3
I need to make an appointment to return the current balance of the employee.
Being that in my modeling I separate the debts and credits of the employee by the type fields 1
for credits and 2
for debts. My query is not bringing the total amount grouped per 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
Perfect Bacco, I understood how to use function syntax
IF
and perfectly met my need.– Dagobe