Ola
Estou editando uma consulta que esta em uma view, preciso que seja exibido a maior data do campo, inseri o max no campo e o group by mas ao executar aparece o erro:
ORA-00979: not a GROUP BY expression
00979. 00000 - "not a GROUP BY expression"
*Cause:
*Action:
Erro na linha: 8 Coluna: 19
Segue a query:
AS
WITH MOT AS (
SELECT NUM_MOTI, NOM_MOTI, DES_MOTI FROM TBMANI0004
)
SELECT MAN.NUM_PROT,
CASE
WHEN UPPER (ASN.NOM_ASNT) LIKE 'ASSIS%' THEN 'SAC'
WHEN UPPER (ASN.NOM_ASNT) LIKE 'GEST_O CAL ATIV%' OR UPPER (MOT.NOM_MOTI) LIKE 'GEST_O CAL ATIV%'
THEN 'CAL-ATV'
ELSE 'MI'
END COD_ORIG_MANIF,
MAN.COD_SITU_MANI,
'Z012' COD_ORG_VENDA,
'Z1' COD_CANAL_DISTR,
'91' COD_SETOR_ATIV,
PES.COD_R3RE_CUST COD_SAP_PES,
NULL NUM_PESS,
MAN.DAT_INCL,
PES.NUM_CLAS,
NVL (NULLIF (MAN.NUM_CANA_ATEN_CUST, 0), MAN.NUM_CANA) NUM_CANA,
MAN.NUM_SEGM,
MAN.NUM_MOTI,
MAN.NUM_ASNT,
MAN.NUM_ASNT_DETA,
NULL COD_CENTRO,
MAN.DAT_INCL DAT_INCL_MANI,
MAN.NUM_PESS_ASSI_TECN_CUST NUM_PESS_ASSI_TECN,
MAX(W5.DAT_PRAZ_EXEC) DAT_ATEN,
MAN.DAT_ATEN_ASSI_TECN_CUST DAT_ATEN,
MAN.DAT_ENCE_MANI DAT_ENCE,
MAN.NUM_PEDI_ORIG_CUST,
MAN.NUM_MANI_ORIG_CUST,
EDR.DES_BAIR,
EDR.DES_CIDA,
EDR.COD_ESTA,
MAN.COD_DDDN_CONT_CUST,
MAN.COD_TELE_CONT_CUST,
MAN.NOM_CONT_CUST,
NULL RESPONS_LIQ,
NULL SUTEC
FROM
TBMANI0001 MAN
INNER JOIN TBPESS0001 PES ON PES.NUM_PESS = MAN.NUM_PESS
INNER JOIN TBENDE0001 EDR ON EDR.NUM_PESS = PES.NUM_PESS AND EDR.NUM_ENDE = PES.NUM_ENDE
INNER JOIN MOT ON MOT.NUM_MOTI = MAN.NUM_MOTI
INNER JOIN TBMANI0005 ASN ON ASN.NUM_ASNT = MAN.NUM_ASNT
INNER JOIN TBWORK0004 W4 ON MAN.NUM_PROT=W4.NUM_PROT
INNER JOIN TBWORK0005 W5 ON W4.NUM_FLUX=W5.NUM_FLUX
WHERE
PES.NUM_CLAS = 26
AND MAN.DAT_INCL >= TO_DATE ('01/01/2013', 'DD/MM/YYYY')
GROUP BY
MAN.NUM_PROT,
MAN.DAT_INCL,
PES.NUM_CLAS,
MAN.NUM_SEGM,
MAN.NUM_MOTI,
MAN.NUM_ASNT,
MAN.NUM_ASNT_DETA,
MAN.DAT_INCL,
MAN.NUM_PESS_ASSI_TECN_CUST,
MAN.DAT_ATEN_ASSI_TECN_CUST,
MAN.DAT_ENCE_MANI,
MAN.NUM_PEDI_ORIG_CUST,
MAN.NUM_MANI_ORIG_CUST,
EDR.DES_BAIR,
EDR.DES_CIDA,
EDR.COD_ESTA,
MAN.COD_DDDN_CONT_CUST,
MAN.COD_TELE_CONT_CUST,
MAN.NOM_CONT_CUST;