根据具有多个选项的条件进行选择

时间:2012-08-10 02:51:19

标签: sql oracle oracle11g aggregate

在提到table_name

之后,在where子句或任何地方之后使用聚合函数我感到很困惑

http://viditkothari.co.in/post/27045365558/sql-commands-1上发布的EMP表

查询信息:
显示所有拥有sal等于任何deptno 30

的emp的emp

建议查询:

select * 
  from employee_4521 
 where sal having (select sal 
                     from employee_4521 
                    where deptno = 30);

返回以下错误:

  

第1行的错误:
  ORA-00920:无效的关系运算符

在星号下标有星号

1 个答案:

答案 0 :(得分:2)

这里似乎没有任何理由使用聚合函数。只需使用INEXISTS

即可
select * 
  from employee_4521 
 where sal in (select sal 
                 from employee_4521 
                where deptno=30);

select * 
  from employee_4521 a
 where exists( select 1
                 from employee_4521 b
                 where b.deptno = 30
                   and a.sal = b.sal );
相关问题