Oracle PL/SQL problem with AS

Asked

Viewed 41 times

2

Good afternoon, I have a question regarding the use of AS in plsql in an oracle database

follows the code:

SELECT CC.NOME, SUM(1) AS QTD_CEL, SUM(CASE WHEN C.STATUS LIKE 'INATIVO' THEN 1 ELSE NULL END) AS QTD_INATIVO , MIN(C.NEW_COL) AS DATA
FROM TB_CLIENTE CC, TB_CONTRATO C 
WHERE C.ID_CLIENTE=CC.ID_CLIENTE
AND QTD_CEL > 1
AND CC.SEGMENTO='EMPRESARIAL'
AND (C.ID_PRODUTO = 304
OR C.ID_PRODUTO = 305)
GROUP BY CC.NOME

and I’m getting the following error:

ORA-00904: "QTD_CEL": identificador inválido
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Erro na linha: 42 Coluna: 5

Apparently he doesn’t identify the ALIAS as an identifier, someone could help me?

1 answer

1

--creio que RESOLVA

SELECT CC.NOME, 
       SUM(1) AS QTD_CEL, 
       SUM(CASE WHEN C.STATUS LIKE 'INATIVO' THEN 1 
                ELSE NULL END) AS QTD_INATIVO , 
MIN(C.NEW_COL) AS DATA
FROM TB_CLIENTE CC, TB_CONTRATO C 
WHERE C.ID_CLIENTE=CC.ID_CLIENTE
AND CC.SEGMENTO='EMPRESARIAL'
AND (C.ID_PRODUTO = 304
OR C.ID_PRODUTO = 305)
GROUP BY CC.NOME,C.STATUS/*citado no case*/
HAVING SUM(1) > 1

Browser other questions tagged

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