有员工信息表emp1(包含以下字段empno-工号,name-姓名,deptno-部门,salary-工资,sex-性别(0代表男性,1代表女性)
请列出所有工资少于同部门男性员工平均工资的女性员工的工号,姓名和部门。
select empno,name,deptno 
    from emp1 x
        where sex = '1' and (         )
在括号中填上适当的语句。

解决方案 »

  1.   

    (salary<(select avg(salary) from emp1 where sex=1 and deptno=x.deptno));
      

  2.   

    salary<(select avg(salary) from emp1 where sex = '0' 
      

  3.   

    ...
    salary<(select avg(salary) from emp1 where sex = '0' and deptno=x.deptno)
      

  4.   


    salary<(select avg(salary) from emp1 where sex = '0' and deptno=x.deptno)
      

  5.   


    salary<(select avg(salary) from emp1 where sex = '0' and deptno=x.deptno)
      

  6.   


    salary<(select avg(salary) from emp1 where sex = '0' and deptno=x.deptno)
      

  7.   

    最后不要加group by deptno 吗?
      

  8.   

    (salary<(select avg(salary) 
                from emp1 
                where sex = '0')
      

  9.   

    SALARY<(SELECT AVG(SALARY) FROM EMP1 Y WHERE SEX='0' AND Y.DEPTNO=X.DEPTNO)
      

  10.   

    不需要的,因为对于查询语句"SELECT AVG(SALARY) FROM EMP1 Y WHERE SEX='0' AND Y.DEPTNO=X.DEPTNO",查询得到的结果集都属于同一部门。
      

  11.   


    salary<(select avg(salary) from emp1 where sex = '0' and deptno=x.deptno)
      

  12.   

    salary<(select avg(salary) from x where sex='0'
      

  13.   


    SQL code
    salary<(select avg(salary) from emp1 where sex = '0' and deptno=x.deptno)
    [/Quote]不要加 group by deptno   用子查询就可以实现要求