dreamsoft_PR 36 Denunciar post Postado 17 Janeiro oi preciso pegar essas duas colunas e so trazer se a outra for maior o resultado select i.codvend, sum(i.vlrtotal) soma_item, ( select sum(c.vlrtotal) from tab_vend c where c.codvend=i.codvend group by c.codvend) soma_venda from tab_item i left join tab_vend w on ( w.codvend = i.codvend) where w.datvend>=:dae group by i.codvend e que quero vereficar se tem algum registro com soma da venda menor que dos itens ja fiz assim nao deu certo (NO FINAL) HAVING ( select sum(c.vlrtotal) from tab_vend c where c.codvend=i.codvend group by c.codvend)< sum(i.vlrtotal) Compartilhar este post Link para o post Compartilhar em outros sites
BigWings 1.445 Denunciar post Postado 17 Janeiro 9 horas atrás, dreamsoft_PR disse: e que quero vereficar se tem algum registro com soma da venda menor que dos itens select i.codvend , w.vlrtotal soma_venda , sum(i.vlrtotal) soma_item from tab_item i left join tab_vend w on (w.codvend = i.codvend) where w.datvend>=:dae group by i.codvend, w.vlrtotal having sum(i.vlrtotal) > w.vlrtotal 1 Compartilhar este post Link para o post Compartilhar em outros sites
dreamsoft_PR 36 Denunciar post Postado 17 Janeiro veio assim Compartilhar este post Link para o post Compartilhar em outros sites
Reinaldo Silveira 16 Denunciar post Postado 25 Janeiro dreamsoft_PR, Você não disse qual banco está utilizando. Mas no geral, você poderia utilizar uma tabela derivada. Algo assim: select * from ( select i.codvend ,sum(i.vlrtotal) soma_item ,(select sum(c.vlrtotal) from tab_vend c where c.codvend = i.codvend group by c.codvend) soma_venda from tab_item i left join tab_vend w on (w.codvend = i.codvend) where w.datvend >= :dae group by i.codvend ) where soma_venda < soma_item Outra alternativa semelhante é utilizar a cláusula WITH Faça uns testes e compartilhe o resultado. Abraço. 1 Compartilhar este post Link para o post Compartilhar em outros sites