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, 20, 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 子查询
子查询和多表查询



 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值