This is table employee with following columns and data and I want to find out the designation whose average salary is greater than 500000.
idnew_table, Designation, Name, Salary
'1', 'ABC', 'anubhav', '500001'
'2', 'ABC', 'utsav', '2'
'3', 'HHHH', 'ddd', '1000000'
'4', 'TT', 'dss', '2'
You can use GROUP BY
and HAVING
as follows:
select designation
from employees
group by designation
having avg(salary) > 500000
You have to change the type of salary column to INT
with CAST(expression AS [data type])
in order to have an AVG
result. Also with HAVING
in sql you can add a condition.
SELECT designation
FROM employees
GROUP BY designation
HAVING avg(cast(salary as int)) >500000
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.