Jump to content
Fórum Script Brasil
  • 0

Ajuda com performance de querie (com data)


ricardo.bezerra

Question

Olá, a querie abaixo, funciona perfeita e rápida, porém, ao inserir os últimos "AND" com o período...ela trava, alguém pode dar dicas do porque e, como solucionar?

Obrigado desde já.

Últimos "AND":

 AND rel.data_inclusao BETWEEN '2015-15-04 00:00:00' AND '2015-15-04 23:59:59'

Querie:

SELECT 
     rel.id_relatorio
    ,rel.id_relatorio_retorno
    ,rel.data_inclusao AS dt_inc
    ,rel.documento
    ,caixa.texto AS id_filial
    ,filiais.loja
    ,caixa.valor AS caixa
    ,caixa.ativo AS ativo
    ,renda.renda_presumida AS renda
    ,score.valor_score AS valor_score
    ,pessoa.idade AS idade
    ,pessoa.situacao AS situacao
    ,msg.mensagem AS mensagem
    ,backoffice.valor AS bckoffice
    ,resultado.valor AS resutlado
    ,CASE WHEN backoffice.valor IS NULL THEN
CASE WHEN rel.id_relatorio_retorno IS NULL THEN 'PDV-REUSO' ELSE 'PDV' 
               END
    ELSE
        'ATENDIMENTO'
    END
FROM
    dec_relatorio rel
        INNER JOIN
    pla_parametros caixa ON rel.id_relatorio = caixa.id_relatorio
        INNER JOIN
    pla_carrefour_filiais filiais ON caixa.texto = filiais.cod_sitef
        LEFT JOIN
    pla_mensagem as msg ON rel.id_relatorio = msg.id_relatorio and msg.id_empresa = 19
        LEFT JOIN
    pla_pessoa_cadastro as pessoa ON rel.id_relatorio = pessoa.id_relatorio
        LEFT JOIN
    pla_score as score ON rel.id_pessoa_score = score.id_score
        LEFT JOIN
    pla_renda_presumida_analise AS renda ON rel.id_renda_presumida_analise = renda.id_renda_presumida_analise AND renda.id_empresa = 19
        LEFT OUTER JOIN
   pla_parametros backoffice ON rel.id_relatorio = backoffice.id_relatorio AND backoffice.tipo = 'BACKOFFICE' AND backoffice.id_empresa = 19
        LEFT OUTER JOIN
    pla_parametros resultado ON rel.id_relatorio = resultado.id_relatorio AND resultado.tipo = 'RESULTADO' AND backoffice.id_empresa = 19
WHERE
    1 = 1 AND caixa.tipo = 'CAIXA' AND rel.id_empresa = 19 AND caixa.id_empresa = 19 AND caixa.ativo = 1
    AND rel.data_inclusao BETWEEN '2015-15-04 00:00:00' AND '2015-15-04 23:59:59'

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

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...