Get Employees Who Are Below Average Salary After A Raise

前端 未结 3 1018
悲哀的现实
悲哀的现实 2021-01-27 04:58

I need to get fname, lname, salary of employees who are $400.00 below the average salary even after geting a 10% salary raise.

I\'m able to get employees who\'s salary i

相关标签:
3条回答
  • 2021-01-27 05:12

    You have the right idea, you just can't use aliases in the where clause like that. Just use the formula directly, and you should be fine. Also, you should probably use <=, and not =:

    select Fname, Lname, Salary, 1.10 * Salary as NewSalary
    from   employee
    where  1.10 * Salary - (select AVG(salary) from employee) <= 400;
    
    0 讨论(0)
  • 2021-01-27 05:13

    select Fname, Lname, Salary, 1.10 * Salary as NewSalary from employee where ((1.10 * Salary) - (select AVG(salary) from employee)) <= 400;

    0 讨论(0)
  • 2021-01-27 05:24

    You can do this with one statement by using HAVING

    select Fname, Lname, AVG(salary * 1.10)    
    FROM employee
    GROUP BY FNAME, LNAME 
    HAVING (AVG(salary) * 1.10) = 400
    

    But I don't understand the concept of average salary of an employee in a table. You could be looking for an average salary of a group of employees perhaps? Or maybe you are storing historical values of salaries, but again I see no purpose of calculating average of that.

    0 讨论(0)
提交回复
热议问题