SELECT * FROM EMPLOYEES WHERE SALARY > (SELECT AVG(SALARY) FROM EMPLOYEES WHERE DEPARTMENT = EMPLOYEES.DEPARTMENT);
时间: 2024-05-20 12:16:17 浏览: 164
mysql命令select.txt
This SQL query selects all columns from the "EMPLOYEES" table where the salary is greater than the average salary of employees in the same department.
The subquery "(SELECT AVG(SALARY) FROM EMPLOYEES WHERE DEPARTMENT = EMPLOYEES.DEPARTMENT)" calculates the average salary for each department, and the main query compares each employee's salary to their department's average salary.
This query can be useful in identifying employees who are earning more than their peers in the same department, and may be candidates for promotions or salary adjustments.
阅读全文