Ir para conteúdo
Fórum Script Brasil

cegonha

Membros
  • Total de itens

    1
  • Registro em

  • Última visita

Sobre cegonha

cegonha's Achievements

0

Reputação

  1. Bom dia a todos, galera to enroscado numa query aqui, preciso efetuar uma agregação na consulta externa e não estou conseguindo select t1.*, t2.* , from (select case when pedcab.estab=101 then 'Matriz' when pedcab.estab=102 then 'Filial' end as Unidade, PEDCFG.pedidoconf as pedidoconf, pedcfg.descricao as descricao_pedido, cidade.uf as UF, cidade.nome as CIDADE, case when (extract(month from dtprazopagto)=1) then 'Janeiro' when (extract(month from pedcab.dtemissao)=2)then 'Fevereiro' when (extract(month from pedcab.dtemissao)=3)then 'Março' when (extract(month from pedcab.dtemissao)=4) then 'Abril' when (extract(month from pedcab.dtemissao)=5) then 'Maio' when (extract(month from pedcab.dtemissao)=6) then 'Junho' when (extract(month from pedcab.dtemissao)=7) then 'Julho' when (extract(month from pedcab.dtemissao)=8) then 'Agosto' when (extract(month from pedcab.dtemissao)=9) then 'Setembro' when (extract(month from pedcab.dtemissao)=10) then 'Outubro' when (extract(month from pedcab.dtemissao)=11) then 'Novembro' when (extract(month from pedcab.dtemissao)=12) then 'Dezembro' end as Mes_Emissao, extract(year from pedcab.dtemissao) as Ano_Emissao, pedcab.dtemissao as Emissao, extract(year from pedcab.dtprazopagto) as Prazo_Pagto_Ano, peditem.seqpedite as SeqpedIte, pedcab.serie as Serie, pedcab.numero as Numero, pedcab.numpedterc N_represent, preprese.descricao as Representante, contamov.nome as cliente, pedcab.numero as Pedido, peditem.item as Item, itemagro.descricao as Item_Desc, pedcab.valormercadoria as Valor_Mercadoria, peditem.quantidade as quantidade, peditem.valorunitario as Valor_Unitario from pedcab left join peditem on pedcab.estab=peditem.estab and pedcab.serie=peditem.serie and pedcab.numero=peditem.numero left join itemagro on peditem.item=itemagro.item left join contamov on pedcab.pessoa=contamov.numerocm inner join pedcfg on pedcab.pedidoconf=pedcfg.pedidoconf left join preprese on pedcab.represent=preprese.represent and pedcab.representestab=preprese.empresa left join cidade on preprese.cidade=cidade.cidade where pedcab.pedidoconf=1 or (pedcab.pedidoconf=7 or (pedcab.pedidoconf=8))) as t1 left join ( select case when peditemnfitem.estab=101 then 'Matriz' when peditemnfitem.estab=102 then 'Filial' end as Unidade, peditemnfitem.serie as Serie, peditemnfitem.numero as Pedido, peditemnfitem.seqpedite as Seqpedite, sum(peditemnfitem.quantidade) as qtdbaixada from peditemnfitem group by peditemnfitem.estab, peditemnfitem.serie, peditemnfitem.numero, peditemnfitem.seqpedite )as t2 on t1.unidade=t2.unidade and t1.Serie=t2.Serie and t1.Pedido=t2.Pedido and t1.Seqpedite=t2.Seqpedite
×
×
  • Criar Novo...