Good evening,
I need to bring the complete subquery result:
(select (valor * 0.05) from tbl_exames) as 'Valor dos Exames',
In a delimiter:
delimiter //
create procedure comissao(idmedico int)
begin
select nome_medico as 'Médico',
(select (valor * 0.05) from tbl_exames) as 'Valor dos Exames',
(select sum(valor * 0.05) from tbl_exames) as 'Valor Total das Comissões'
from tbl_medico where id_medico = idmedico;
end //
delimiter ;
Where the error occurs: Error Code: 1242. Subquery returns more than 1 row.
It will list all the values of the exams being 5% of it.
Edit:
I'd like it to look like this:
Doctor - name
Exam value - value1, value2, value3, etc.
Total Commissions Amount - Sum of above values
Edit2:
It would be like this, but close to what I expected:
delimiter //
create procedure comissao(idmedico int)
begin
select nome_medico as 'Médico',
(select sum(valor * 0.05) from tbl_exames) as 'Valor Total das Comissões'
from tbl_medico where id_medico = idmedico union
select tipo as 'Exame', (valor * 0.05) as 'Valor da Comissão' from
tbl_exames;
end //
delimiter ;