Jump to content
Fórum Script Brasil
  • 0

Consulta Otimizada


Seben

Question

Bom dia , criei um sql para listar na mesma consulta valores vendidos por histórico e seus totais. Gostaria de saber se tem uma forma mais otimizada de fazer isto.

select cd_filial,to_char(dt_mvto,'dd/mm/yyyy')Data_Transacao,

to_char (SUM(CASE WHEN cd_historico in(181) THEN (vl_historico) ELSE 0 END),'9990D99')as Visa_Eletron,

to_char (SUM(CASE WHEN cd_historico in(324) THEN (VL_HISTORICO) ELSE 0 END),'9990D99')as Maestro,

to_char (SUM(CASE WHEN cd_historico in(181,324) THEN (VL_HISTORICO) ELSE 0 END),'9990D99')as TOTAL_VISA_ELETRON_MAESTRO,

to_char (SUM(CASE WHEN cd_historico in(443) THEN (VL_HISTORICO) ELSE 0 END),'9990D99')aS VISA,

to_char (SUM(CASE WHEN cd_historico in(444) THEN (VL_HISTORICO) ELSE 0 END),'9990D99')as MASTERCARD,

to_char (SUM(CASE WHEN cd_historico in(443,444) THEN (VL_HISTORICO) ELSE 0 END),'9990D99')as TOTAL_VISA_MASTERCARD

from scxmvhis where dt_mvto between '12/12/2012' and '12/12/2012' and cd_historico in (181,324,443,444)

group by

cd_filial,

dt_mvto

order by cd_filial

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Bom dia , preciso de ajuda neste sql acima:

preciso que na coluna TOTAL_VISA_MASTERCARD seja listado um cálculo:

Exemplo:

to_char (SUM(CASE WHEN cd_historico in(443) THEN (VL_HISTORICO) ELSE 0 END),'9990D99')aS VISA,

to_char (SUM(CASE WHEN cd_historico in(519) THEN (vl_historico) ELSE 0 END),'9990D99')as ESTORNO_Visa_Eletron,

to_char (SUM(CASE WHEN cd_historico in(443)THEN (VL_HISTORICO)ELSE 0 END),'9990D99')as TOTAL_VISA_MASTERCARD

Quero que o valor das entradas (443) seja diminuído do valor das saídas (519) e seja listado na coluna TOTAL_VISA_MASTERCARD.

Link to comment
Share on other sites

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
      152.2k
    • Total Posts
      652k
×
×
  • Create New...