+ 1
Can we use this Select salary From employees Where salary>AVG(salary);?
12 Réponses
+ 6
Try this!
SELECT first_name, salary FROM employees WHERE salary > ( SELECT AVG (salary) FROM employees) ORDER BY salary DESC;
0
no , we can't use aggregate function in where clause
0
no.its wrong.
0
No, you would need a subquery for this.
So you could do:
SELECT salary FROM employees WHERE salary > (AVG(salary) FROM employees)
0
🐱
0
no ,it is wrong .we can't use aggregate function in where clause
0
No
0
declare @avg_salary as decimal
set @avg_salary = (select avg (salary) from employees)
select salary from employees where salary > @avg_salary
this is an untested query but i believe this will het you what you are after.
0
we can use aggregate function with where clause.but here in avg(salary),salary is from employee. first thing,it is a single query clause.so we should include parantheses .
it should be like this select salary from employee where salary>(select AVG(salary)from employee );
0
Answer is coming up in the next explanation :)
0
you should use HAVING clause instead of WHERE clause when working on search criteria based on aggregate function, I haven't tested the below query but give it a try
SELECT * FROM EMPLOYEE
HAVING SALARY > AVG(SALARY)
0
no.. its a group function