Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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_Oracle_Oracle11g_Aggregate - Fatal编程技术网

Sql 基于具有多个选项的条件进行选择

Sql 基于具有多个选项的条件进行选择,sql,oracle,oracle11g,aggregate,Sql,Oracle,Oracle11g,Aggregate,我完全搞不懂在where子句之后使用聚合函数,或者在提到表名称之后的任何地方使用聚合函数 发布在上的EMP表 查询信息: 显示sal等于deptno 30的任何emp的所有emp 建议查询: select * from employee_4521 where sal having (select sal from employee_4521 where deptno = 30); 返回以下错误: 第

我完全搞不懂在where子句之后使用聚合函数,或者在提到表名称之后的任何地方使用聚合函数

发布在上的EMP表

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

建议查询:

select * 
  from employee_4521 
 where sal having (select sal 
                     from employee_4521 
                    where deptno = 30);
返回以下错误:

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


在having子句的“h”下标记星号后,似乎没有任何理由在此处使用聚合函数。只需使用IN或EXISTS


如果您需要问第二个问题,请随意创建第二个线程。如果你在一个线程中问多个不相关的问题,事情会变得复杂。非常感谢你提供了这个解决方案,但我不明白在选择子查询之后,第二个解决方案中1的用途。我的一个朋友建议:选择*from employee_4521,其中sal=any选择sal from employee_4521,其中deptno=30;这是正确的吗?@viditkothari-使用ANY将是非常规的,但本质上与查询的IN版本相同。EXISTS查询中的1是不相关的-您可以在那里选择任何需要的内容。EXISTS子句只检查子查询是否至少返回一行。你可以在那里选择你想要的任何东西。
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 );