Can we use this Select salary From employees Where salary>AVG(salary);? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can we use this Select salary From employees Where salary>AVG(salary);?

21st Nov 2015, 7:32 AM
Akash Potdar
Akash Potdar - avatar
12 Answers
+ 6
Try this! SELECT first_name, salary FROM employees WHERE salary > ( SELECT AVG (salary) FROM employees) ORDER BY salary DESC;
2nd Jul 2016, 3:02 PM
Abdul Hakim Sabery
Abdul Hakim Sabery - avatar
0
no , we can't use aggregate function in where clause
17th Apr 2016, 6:22 AM
sarabjeet
sarabjeet - avatar
0
no.its wrong.
26th Apr 2016, 4:21 AM
bangarubabu
0
No, you would need a subquery for this. So you could do: SELECT salary FROM employees WHERE salary > (AVG(salary) FROM employees)
21st Jun 2016, 11:24 PM
Gaurav Prinja
Gaurav Prinja - avatar
0
🐱
27th Jun 2016, 5:04 PM
Edzel Rose
0
no ,it is wrong .we can't use aggregate function in where clause
28th Jun 2016, 6:25 AM
Komal Ghadage
0
No
28th Jun 2016, 1:40 PM
4xMafole
4xMafole - avatar
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.
1st Jul 2016, 4:05 AM
Stevan Camp
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 );
16th Jul 2016, 5:15 AM
sangeetha
0
Answer is coming up in the next explanation :)
26th Jul 2016, 8:05 PM
Nora Bukovinszky
Nora Bukovinszky - avatar
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)
25th Aug 2016, 2:14 PM
naresh
0
no.. its a group function
8th Nov 2016, 2:09 PM
Soutik
Soutik - avatar