0

I need to find the IDs and names of the employees whose salaries are at least 10% higher than the average salary of all employees. I can't get the code to work with the 10% higher than the average. I know how to get the average, but when I run my particular code, I get all names and know that it's not running correctly.

Here is my query:

Select employees.eid, 
       CONCAT(efirstName, 
       ' ', eLastName) AS Name 
from employees 
GROUP BY employees.salary 
HAVING employees.salary > avg(salary * .10); 

I have also tried:

Select employees.eid, 
       CONCAT(eFirstName, 
       ' ', 
       eLastName AS Name 
FROM employees 
GROUP by eLastName 
HAVING avg(salary) > avg(salary * .10);

enter image description here

3
  • What did you try?
    – Marco
    Aug 24, 2017 at 14:05
  • Select employees.eid, CONCAT(efirstName, ' ', eLastName) AS Name from employees GROUP BY employees.salary HAVING employees.salary > avg(salary * .10); I have also tried: Select employees.eid, CONCAT(eFirstName, ' ', eLastName AS Name FROM employees GROUP by eLastName HAVING avg(salary) > avg(salary * .10);
    – Ashley
    Aug 24, 2017 at 14:21
  • @Marco See above comment
    – Ashley
    Aug 24, 2017 at 14:40

2 Answers 2

3

Using a simple subquery should help with this:

SELECT e.eid, CONCAT(efirstname, ' ', e.elastname) name
FROM employees e
WHERE e.salary > (SELECT AVG(salary) FROM employees) * 1.10
1
  • @Ashley Then give it the check mark
    – paparazzo
    Aug 24, 2017 at 16:47
-2

Can u try this:

    SELECT e.eid, concat(e.eFirstName, ' ', e.LastName) as name
    FROM employees e
    WHERE e.salary > AVG(e.salary) * 0.1;
1
  • I get invalid use of group function
    – Ashley
    Aug 24, 2017 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.