Jump to content
Fórum Script Brasil
  • 0

Varios selects com datas, erro nas comas


Question

Caros senhores, estou com dificuldades em realizar uma query, quando adiciono uma tabela, o select calcula todas as demais e inclusive a mesma dobrada ou triplicada, sera que conseguem me ajuda?

esta é a dita cuja que já esta me deixando de cabelos em pé

 

select to_char(trunc(acv.dtfinal, 'Month'), 'MM'),
to_char(acv.dtfinal, 'Month'),
sum(abast.litros),
sum(abast.vlrlitro),
sum(despos.TotalOs),
sum(finan.vlr1),
sum(frete.Vlrreceber),
sum(acv.vlrcomissao),
avg(acv.perccomissao),
avg(acv.ad_mediafinal),
sum(acv.vlrbasecalccomissao),
sum(acv.vlrcomissaofrete),
avg(acv.ad_indice),
sum(acv.ad_qtdkm) AS KMINFORMADO,
sum(NVL(acv.AD_QTDKMROTA + acv.AD_CORKMROT, acv.AD_QTDKMROTA)) AS KMROTA,
acv.codveiculo,
vei.placa,
vei.anofabric,
vei.anomod,
acv.Ad_NModelo
from tmsacv acv
inner join tgfvei vei
on (vei.codveiculo = acv.codveiculo)
LEFT JOIN (select sum(item.qtdlitro) AS litros,
sum(item.vlrtotal) As vlrlitro,
abt.nuacerto As nuabt
from tmsacvabt abt, tcfabtite item
where item.idabt = abt.idabt
and item.codprod = 693
group by abt.nuacerto) abast
ON abast.nuabt = acv.nuacerto
LEFT JOIN (select ctf.nuacerto As nufrete,
sum(frete.ad_vlrreceber) As Vlrreceber
from tmsacvctf ctf, tmsctfrete frete
where ctf.codctf = frete.codigo
group by ctf.nuacerto) frete
ON frete.nufrete = acv.nuacerto
LEFT JOIN (select cab.nuoscab As nuoscab, sum(item.vlrtot) As TotalOs
from tmsacvos acvos, tgfcab cab, tgfite item
where cab.nuoscab = acvos.nuos
and item.nunota = cab.nunota
group by cab.nuoscab) despos
ON despos.nuoscab = acv.nuacerto
LEFT JOIN (select to_char(trunc(dtneg, 'Month'), 'MM'),
to_char(dtneg, 'Month'),
sum(vlrdesdob) AS vlr1,
codveiculo
from tgffin
where tgffin.dtneg between ('01/01/2020') and ('20/03/2020')
and tgffin.recdesp = -1
group by trunc(tgffin.dtneg, 'Month'),
to_char(tgffin.dtneg, 'Month'),
codveiculo
order by trunc(tgffin.dtneg, 'Month'),
to_char(tgffin.dtneg, 'Month')) finan
on finan.codveiculo = vei.codveiculo

where acv.dtfinal between ('01/01/2020') and ('20/03/2020')
group by acv.codveiculo,
vei.placa,
trunc(acv.dtfinal, 'Month'),
to_char(acv.dtfinal, 'Month'),
acv.Ad_NModelo,
vei.anofabric,
vei.anomod
order by acv.codveiculo, trunc(acv.dtfinal, 'Month')

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148910
    • Total Posts
      645016
×
×
  • Create New...