Remove SQL CASE parameter agreement results

Asked

Viewed 30 times

0

As follows the query below, I need to remove from the SQL query the results that have the field CLIENTE_UNICO EQUAL TO 'MULTIPLE PURCHASES IN THE PERIOD'.

SELECT
NFE.CD_CLIENTE AS "COD. DO CLIENTE",
EMP.NOME_COMPLETO AS "CLIENTE",
(
CASE COUNT(NFE.NF) WHEN 1
THEN 'ÚNICA COMPRA NO PERÍODO'
ELSE 'MÚLTIPLAS COMPRA NO PERÍODO'
END)
AS "CLIENTE_UNICO"

FROM FANFISCA NFE
LEFT JOIN GEEMPRES EMP ON EMP.CD_EMPRESA = NFE.CD_CLIENTE

WHERE NFE.DT_EMISSAO BETWEEN TO_DATE('01/05/2020', 'DD/MM/YYYY') AND TO_DATE('31/08/2020', 'DD/MM/YYYY')

GROUP BY NFE.CD_CLIENTE, EMP.NOME_COMPLETO

Below is also the result of the consultation.

inserir a descrição da imagem aqui

Any idea how to "delete" these results with "MULTIPLE PURCHASE IN THE PERIOD"?

1 answer

1


    SELECT
    NFE.CD_CLIENTE AS "COD. DO CLIENTE",
    EMP.NOME_COMPLETO AS "CLIENTE",
COUNT(NFE.NF)
    AS "QUANTIDADE_COMPRAS_PERIODO"
    
    FROM FANFISCA NFE
    LEFT JOIN GEEMPRES EMP ON EMP.CD_EMPRESA = NFE.CD_CLIENTE
    
    WHERE NFE.DT_EMISSAO BETWEEN TO_DATE('01/05/2020', 'DD/MM/YYYY') AND TO_DATE('31/08/2020', 'DD/MM/YYYY')
    
    GROUP BY NFE.CD_CLIENTE, EMP.NOME_COMPLETO,COUNT(NFE.NF)
    HAVING COUNT(NFE.NF)= 1

see if this is the result you expected

Browser other questions tagged

You are not signed in. Login or sign up in order to post.