微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

23-Oracle入门之空值和SQL语句优化

1 空值知识点梳理 1 含有空值的表达式 都是空 2 null!=null 不能这个语法 --- null和空值在一起 3 null的第三点:如果集合中含有空值,不能使用not in 操作符; 但可使用in操作符 select * from emp where deptno in (10,20,null) 查询部门编号是10 || 20 || nul任何部门都不是 if (deptno==10 || deptno==20 || deptno==null) { } select * from emp where 1>2 where deptno not in (10,null) / ---查询部门编号不在10,不在20 不在null的员工信息 if (deptno!=10 && deptno!=20 && deptno!=null) { } / 4 空值null的第四点补充:排序的时,如何将null排在最后. 按照奖金进行排序查询,员工信息 nulls last 2 sql语言优化知识点梳理 1 写*号 还是都写出来好 select * from emp; select empno,ename,comm from emp; 2 解析顺序 select ... from tab1,tab2 where con1>1 and con2<2222 and col3='aaaa' <----- where condition1 and condition2 where condition2 and condition1 oracle解析where条件时,从右向左. 如果右条件已经是假,左边的就不需要解析了.可以做sql优化 3 先分组在过滤 还是先条件检索在分组 --求10部门的平均工资 //先条件过滤,在求结果 select deptno,avg(deptno) --速度快 from emp where deptno = 10 group by deptno select deptno,avg(deptno) from emp group by deptno having deptno = 10 4 子查询查询和多表查询

原文地址:https://www.jb51.cc/oracle/210939.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐