1.1 查找空值
select * from emp where comm is NULL 正确的写法
select * from emp where comm=NULL 错误的写法
1.2 NULL 不支持加、减、乘、除、大小比较、相等比较
1.3 处理空值
select nvl(comm,0) from emp where nvl(comm,0)>=0 单个空值处理
select coalesce(c1,c2,c3,c4) as c from emp 多个空值处理
1.4 查询满足多个条件的行
在查询条件后面用or关键字,把每一组的条件用括号连起来
select * from emp where age>12 or score>90 or (sex='1' and class='1')
1.5 为查询返回列取有意义的别名
1.6 在where 子句中引用取别名的列
select * from (select sal as 工资,comm as 提成 from emp)x where 工资<1000 写报表时候用
1.7 拼接列用 ||
1.8 在select 语句中使用条件逻辑
select ename,sal,case when sal<=2000 then '过低' when sal>=4000 then '过高' else 'ok' end as status from emp where deptno=10
1.9限制返回的行数
select * from emp where rownum<=2
1.10 以指定次序排序
select empno,ename,age from emp where deptno=10 order by age asc
select empno,ename,age from emp where deptno=10 order by 3 asc 按返回的第三列排序
select empno,deptno,sal,ename from emp order by 2 asc ,3 desc