Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group function is not allowed here

When I run the following query, I get

ORA-00934: group function is not allowed here

what is the problem ?

select c.Numcom,c.Nompr,c.salaire_fix
from commercialv c,comercialv c1
where c.salaire_fix=(max(c1.salaire_fix) );
like image 338
user3093583 Avatar asked Jan 21 '15 21:01

user3093583


People also ask

What does group function is not allowed here mean?

ORA-00934: group function is not allowed here Cause: One of the group functions, such as AVG, COUNT, MAX, MIN, SUM, STDDEV, or VARIANCE, was used in a WHERE or GROUP BY clause. Action: Remove the group function from the WHERE or GROUP BY clause.

Which of the following is not group function?

Which of the following is NOT a GROUP BY function? Answer: C. NVL is a general function used to provide alternate value to the NULL values. The functions MAX, MIN and AVG can be used as GROUP BY functions.

What is Group function in SQL?

The SQL GROUP BY Statement The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group the result-set by one or more columns.

How do I fix Ora 00937 Not a single group group function?

To resolve the error, you can either remove the group function or column expression from the SELECT clause or you can add a GROUP BY clause that includes the column expressions. Remember, if you are using an aggregate function in your select query then you must also have a GROUP BY clause.


2 Answers

You cannot use an aggregate function in a WHERE clause.

Given your use case, you probably want a subquery:

select c.Numcom,c.Nompr,c.salaire_fix
from commercialv c
where c.salaire_fix=(select max(salaire_fix) from comercialv);

The rational is that aggregate functions works on a set. The WHERE clause on the other hand, has only access to the data of one row.

like image 81
Sylvain Leroux Avatar answered Sep 23 '22 10:09

Sylvain Leroux


You can do what you want with analytic functions:

select Numcom, Nompr, salair_fix
from (select c.Numcom, c.Nompr, c.salaire_fix,
             max(c.salaire_fix) over () as maxs
      from commercialv c
     ) c
where c.salaire_fix = c.maxs;

As for your query, aggregation functions are not permitted in the where clause.

like image 42
Gordon Linoff Avatar answered Sep 20 '22 10:09

Gordon Linoff