ORA-00979: not a GROUP BY expression – Oracle PL/SQL Tutorial
Mục Lục
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 powhere p.BRAND_ID=pb.BRAND_IDand p.PHONE_ID=po.PHONE_IDgroup 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 powhere p.BRAND_ID=pb.BRAND_IDand p.PHONE_ID=po.PHONE_IDgroup by p.PHONE_ID, p.PHONE_NAME, pb.NAME