SELECT nome,
(SELECT SUM(status)
FROM TabelaEmprestimo e
where e.id_cliente = c.id_cliente
) as Total_Emprestimos_Ativos
FROM TabelaClientes c
ORDER BY Total_Emprestimos_Ativos DESC;
SELECT nome,
(SELECT SUM(status)
FROM TabelaEmprestimo e
where e.id_cliente = c.id_cliente
) as Total_Emprestimos_Ativos
FROM TabelaClientes c
ORDER BY Total_Emprestimos_Ativos DESC;
Olá, Rubens, tudo bem?
Obrigada por compartilhar sua solução no fórum! Com certeza inspirará outros alunos.
. Continue empenhado e não hesite em retornar ao fórum sempre que tiver dúvidas ou quiser compartilhar mais insights.
Abraços e bons estudos!