0

Hi I am getting below error: "Selected non-aggregate values must be part of the associated group" even after Assigning GROUP BY

    SELECT OA.CustNmr 
,TRIM(COALESCE(A.AcctName,' ') ||' '|| COALESCE(A.Acct2Name,' ') )AS AcctStyling 
,COUNT(*) OVER(PARTITION BY  OA.CustNmr, A.LocationNR, AcctStyling)  AS CNT_Cust
    FROM wa.tsn_Open OA
    JOIN Account1 A ON OA.AcctNr = A.AcctNr
    WHERE AcctStatCd = 'O' --Open
    GROUP BY 1

Any insight is highly appreciated.

Sudha
  • 1
  • Does this answer your question? [Selected non-aggregate values must be part of the associated group](https://stackoverflow.com/questions/17378877/selected-non-aggregate-values-must-be-part-of-the-associated-group) – GrandMasterFlush Sep 24 '21 at 23:40
  • What part of the error message do you not understand? It seems pretty clear: the `select` columns are inconsistent with the `group by` columns. – Gordon Linoff Sep 25 '21 at 00:22
  • Well, `AcctStyling` and `LocationNR` are not aggregates nor in the `GROUP BY`. The window function is computed after the `GROUP BY`. What are you really trying to do? Please edit the question or delete it and post another. – Fred Sep 25 '21 at 02:59
  • Thanks everyone I understood where my mistake in my code and corrected it. Now it is working fine. I added the attributes in SELECT in GROUP BY statement: GROUP BY OA.CustNr,AcctStyling, A.LocationID – Sudha Sep 25 '21 at 20:03

0 Answers0