我需要搜索超过平均工资的员工的姓名和姓名

时间:2019-02-06 18:07:33

标签: mysql sql

<p>

程序输出

SELECT DISTINCT employee.lname, employee.fname
FROM employee, department
WHERE salary > (SELECT AVG(employee.salary)
FROM employee, department
WHERE employee.dno = department.dnumber);

正确的输出

lname   fname
Wong    Franklin
Wallace Jennifer
Narayan Ramesh
Borg    James

1 个答案:

答案 0 :(得分:0)

使用始终正确的显式标准JOIN语法并限定您的列名:

SELECT DISTINCT e.lname, e.fname
FROM employee e INNER JOIN 
     department d
     ON d.dnumber = e.dno 
WHERE e.salary > (SELECT AVG(e1.salary)
                  FROM employee e1 INNER JOIN 
                       department d1
                       ON d1.dnumber = e1.dno 
                 );