ORA-00979: not a GROUP BY expression
Oracle PL/SQL error message: ORA-00979: not a GROUP BY expression.
Cause:
The GROUP BY clause does not contain all the expressions in the SELECT clause.
SELECT expressions that are not included in a group function(like AVG, COUNT, MAX, MIN, SUM, STDDEV or VARIANCE) must be listed in the GROUP BY clause.
Solution:
Include in the GROUP BY clause all SELECT expressions that are not group function arguments.
Example:
select p.PHONE_ID, p.PHONE_NAME model, pb.NAME brand, sum(po.AMOUNT) from phones p, phone_brands pb, phone_orders po where p.BRAND_ID=pb.BRAND_ID and p.PHONE_ID=po.PHONE_ID group by p.PHONE_ID
Output:
ORA-00979: not a GROUP BY expression
Correct:
select p.PHONE_ID, p.PHONE_NAME model, pb.NAME brand, sum(po.AMOUNT) from phones p, phone_brands pb, phone_orders po where p.BRAND_ID=pb.BRAND_ID and p.PHONE_ID=po.PHONE_ID group by p.PHONE_ID, p.PHONE_NAME, pb.NAME