sql >> Database teknologi >  >> RDS >> Oracle

ORA-00979:ikke et GROUP BY-udtryk, når jeg udfører min sql

Problemet er, at du bestiller efter noget, der ikke er i din group by klausul.

For eksempel virker dette

SQL> with testGroup as ( select 1 as one, 2 as two from dual)
  2  select one
  3  from testGroup
  4  group by one;

       ONE
----------
         1

Hvis du order by en kolonne, der ikke er i din group by klausul:

SQL> with testGroup as ( select 1 as one, 2 as two from dual)
  2  select one
  3  from testGroup
  4  group by two;
select one
       *
ERROR at line 2:
ORA-00979: not a GROUP BY expression

Hvis du redigerer group by klausul for at håndtere den kolonne, du har brug for i order by :

SQL> with testGroup as ( select 1 as one, 2 as two from dual)
  2  select one
  3  from testGroup
  4  group by one, two;

       ONE
----------
         1

SQL>


  1. Databasedesign til kommentarer og svar

  2. efterfølge hvor dato klausul

  3. tilbagevendende faktureringssystem

  4. Sådan ser du resultatet fra mysql-forespørgsel i netbeans