Fórum select max em um campo calculado #280782
09/05/2005
0
select (select sum(notas.valor_total) from notas where (notas.cliente_id = clientes.cliente_id) and notas.lanca_id = 3) TotalPEd, clientes.*
from CLIENTES
como poderia fazer para pegar o maior valor do campo TotalPed tentei algo do tipo:
select max(select sum(notas.valor_total) from notas where (notas.cliente_id = clientes.cliente_id) and notas.lanca_id = 3) TotalPEd, clientes.*
from CLIENTES
só que não deu certo
Steve_narancic
Curtir tópico
+ 0Posts
09/05/2005
Gandalf.nho
Gostei + 0
09/05/2005
Steve_narancic
utilizo firebird 1.5, poderia me dar uma pequena explicação de como fazer isto?
Gostei + 0
09/05/2005
Gandalf.nho
CREATE VIEW TotalNotas ( cliente_id, lanca_id, soma_valor_total) AS SELECT cliente_id, lanca_id, sum(notas.valor_total) FROM notas;
E depois monte a query final em cima da view, assim:
select MAX(TotalNotas.soma_valor_total) TotalPed, clientes.* FROM TotalNotas INNER JOIN clientes ON TotalPed.cliente_id = clientes.cliente_id WHERE TotalNotas.lanca_id = 3
Só não testei o código.
Gostei + 0
09/05/2005
Steve_narancic
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)