“oracle ”中 “having ”后面可以跟and吗?

“oracle ”中 “having ”后面可以跟and吗?,第1张

1 having后可以接and\x0d\x0a\x0d\x0aSQL>select deptno from emp group by deptno having deptno=10 and deptno>1\x0d\x0a\x0d\x0aDEPTNO\x0d\x0a----------\x0d\x0a10\x0d\x0a\x0d\x0a2 SQL分组前可以使用where,SQL分组后只能用having筛选条件,即:出现group by分组,必须用having才能筛选\x0d\x0a\x0d\x0aSQL>select deptno from emp where sal>100 group by deptno\x0d\x0a\x0d\x0aDEPTNO\x0d\x0a----------\x0d\x0a30\x0d\x0a20\x0d\x0a10\x0d\x0a \x0d\x0aSQL> select deptno from emp group by deptno where sal>100\x0d\x0a select deptno from emp group by deptno where sal>100\x0d\x0a*\x0d\x0aERROR at line 1:\x0d\x0aORA-00933: SQL command not properly ended\x0d\x0a\x0d\x0aSQL> select deptno from emp group by deptno where deptno>1\x0d\x0a select deptno from emp group by deptno where deptno>1\x0d\x0a*\x0d\x0aERROR at line 1:\x0d\x0aORA-00933: SQL command not properly ended\x0d\x0a\x0d\x0aSQL> select deptno from emp group by deptno having deptno>1\x0d\x0a\x0d\x0aDEPTNO\x0d\x0a----------\x0d\x0a30\x0d\x0a20\x0d\x0a10

having子句和group by一起使用,紧跟在group by的后边,having子句可以使用结果集中的列,也可以使用聚合函数(max、min、count、sum、svg)。having的作用是对分组后的结果进行过滤。这里在提一下where,where是对每一行进行过滤的,查询出符合where条件的每一行。having是对查询出结果集分组后的结果进行过滤。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9899957.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存