Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 从表中检索信息_Sql - Fatal编程技术网

Sql 从表中检索信息

Sql 从表中检索信息,sql,Sql,我需要检索工资高于其部门平均工资的员工的信息。。。我们有10个、20个、30个、40个、50个。。。如此下去。在这里,我只为一个部门找到了我需要的东西。(40)我怎样才能为尽可能多的部门做到这一点 这是我的疑问: SELECT * FROM EMPLOYEE where (Department_ID='40')and ( employee_salary > (select avg(employee_salary) from EMPLOYEE where Depart

我需要检索工资高于其部门平均工资的员工的信息。。。我们有10个、20个、30个、40个、50个。。。如此下去。在这里,我只为一个部门找到了我需要的东西。(40)我怎样才能为尽可能多的部门做到这一点

这是我的疑问:

SELECT  * FROM    EMPLOYEE where (Department_ID='40')and 
 (
 employee_salary > 
  (select avg(employee_salary) from EMPLOYEE  where  Department_ID='40')   
 )
数据表

尝试此查询

select * from EMPLOYEE as e1
where e1.employee_salary > (select avg(employee_salary) 
                         from EMPLOYEE as e2 
                         where e1.department_id=e2.department_id
                         group by Department_id)
请尝试此查询

select * from EMPLOYEE as e1
where e1.employee_salary > (select avg(employee_salary) 
                         from EMPLOYEE as e2 
                         where e1.department_id=e2.department_id
                         group by Department_id)
希望这样就行了,

    SELECT  emp.* FROM    EMPLOYEE emp where emp.employee_salary >
      (  select avg(employee_salary) from EMPLOYEE new1 
         where emp.Department_ID=new1.Department_ID 
         group by  Department_ID  
      ) 
希望这样就行了,

    SELECT  emp.* FROM    EMPLOYEE emp where emp.employee_salary >
      (  select avg(employee_salary) from EMPLOYEE new1 
         where emp.Department_ID=new1.Department_ID 
         group by  Department_ID  
      ) 
您可以尝试以下方法:

    SELECT  *, avg(employee_salary) as average_salary 
FROM    EMPLOYEE 
where Department_ID='40' 
having average_salary<employee_salary
选择*,平均(员工工资)作为平均工资
来自员工
哪个部门?'u ID='40'
拥有平均工资您可以尝试以下方法:

    SELECT  *, avg(employee_salary) as average_salary 
FROM    EMPLOYEE 
where Department_ID='40' 
having average_salary<employee_salary
选择*,平均(员工工资)作为平均工资
来自员工
哪个部门?'u ID='40'

让平均工资先提供您的表格结构。先提供您的表格结构。非常感谢您的帮助!那么您创建了两个表来进行比较?我说的对吗?@user1915345他没有创建两个表。他使用的是同一张表,有不同的别名。所以这张桌子实际上只是在和自己比较。非常感谢你的帮助!那么您创建了两个表来进行比较?我说的对吗?@user1915345他没有创建两个表。他使用的是同一张表,有不同的别名。所以这个表实际上只是和它自己比较。