Write a query in SQL to list the employees whose salary is less than the salary of his manager but more than the salary of any other manager
- برمجة سي كيو ال sql
- 2021-09-07
- mhanasmh00489829403
الأجوبة
SELECT DISTINCT W.emp_id,
W.emp_name,
W.salary
FROM
(SELECT w.emp_id,
w.emp_name,
w.salary
FROM employees w,
employees m
WHERE w.manager_id = m.emp_id
AND w.salary<m.salary) W,
(SELECT *
FROM employees
WHERE emp_id IN
(SELECT manager_id
FROM employees)) A
WHERE W.salary > A.salary;
Sample Output:
emp_id | emp_name | job_name | manager_id | hire_date | salary | commission | dep_id | emp_id | emp_name | job_name | manager_id | hire_date | salary | commission | dep_id --------+----------+----------+------------+------------+---------+------------+--------+--------+----------+-----------+------------+------------+---------+-------------+-------- 66928 | BLAZE | MANAGER | 68319 | 1991-05-01 | 2750.00 | | 3001 | 68319 | KAYLING | PRESIDENT | | 1991-11-18 | 6000.00 | | 1001 65646 | JONAS | MANAGER | 68319 | 1991-04-02 | 2957.00 | | 2001 | 68319 | KAYLING | PRESIDENT | | 1991-11-18 | 6000.00 | | 1001 (2 rows)
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال