title: Oracle --> NOT A GROUP BY EXPRESSION ERROR
body: <p>Below is my query. I am not sure what cause the Not A group by expression error. Any help is much appreciated. =)</p>
  
  <pre><code>SELECT 
      DTA_PRODUCAO AS AF002_DTA_PRODUCAO
  ,   COD_MATERIAL AS AD001_COD_MATERIAL 
  ,   COD_FILIAL AS AD004_COD_FILIAL
  ,   NVL(SUM(DQTD_CONSUMOT),0)  AS AF002_DQTD_CONSUMOT
  ,  (SELECT NVL(SUM(DQTD_CONSUMOT),0) FROM MYDB.DSO_TERMICO M WHERE M.COD_FILIAL = D.COD_FILIAL AND M.CODPRO = D.COD_MATERIAL   AND M.ZTL_DATA &gt;= SUBSTR(D.DTA_PRODUCAO,0,6)||'01' AND M.ZTL_DATA &lt;= D.DTA_PRODUCAO) AS AF002_MQTD_CONSUMOT
  ,  (SELECT NVL(SUM(DQTD_CONSUMOT),0) FROM MYDB.DSO_TERMICO M WHERE M.COD_FILIAL = D.COD_FILIAL AND M.CODPRO = D.COD_MATERIAL   AND M.ZTL_DATA &gt;= SUBSTR(D.DTA_PRODUCAO,0,4)||'0101' AND M.ZTL_DATA &lt;= D.DTA_PRODUCAO) AS AF002_AQTD_CONSUMOT
  FROM
      (SELECT 
         DTA_PRODUCAO
         ,CODPRO AS COD_MATERIAL 
         ,COD_FILIAL AS COD_FILIAL 
        , CASE WHEN DAUX.ZTL_DATA = TMP.DTA_PRODUCAO THEN DAUX.DIACONSUMO ELSE 0 END AS DQTD_CONSUMOT
        FROM MYDB.DSO_TERMICO DAUX
        INNER JOIN (SELECT DISTINCT MYDB.DSO_TERMICO.ZTL_DATA AS DTA_PRODUCAO FROM MYDB.DSO_TERMICO) TMP ON SUBSTR(TMP.DTA_PRODUCAO,1,4)=SUBSTR(DAUX.ZTL_DATA,1,4))
    D
    GROUP BY 
    DTA_PRODUCAO,
    COD_MATERIAL,
    COD_FILIAL
    ORDER BY 2,1; 
  </code></pre>