一、表结构:
1、 按子串排序
select ename,job from emp order by SUBSTR(job ,LENGTH(job)-1);
2、使用if-else语句操作
select ename,sal,case
when sal<='200' then 'UNDERPAID'
when sal>='4000' then 'OVERPPAID'
ELSE 'ok'
end as status from emp;
3、从表中随机获取5行数据
select ename,job from emp order by rand() limit 5
4、查找null值
select * from emp where comm is null;
5、将null值转为实际值,如果有值就显示,如果是null就显示0;(两种方法)
select coalesce(comm,0) from emp;
select case when comm is not null then comm
else 0 end from emp;