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