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) );
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 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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With