1.在where字句中使用别名。- select sal as salary, comm as commission
- from emp
- where salary < 5000
- select
- from (
- select sal as salary, comm as commission
- from emp
- ) x
- where salary < 5000
2.多字段合并查询- select concat(name,' age is ', age) as ageInfo from person;
3.新增加一列,内容由其他部分计算得出-
-
- select name,age,
- case when age<20 then 'too young'
- when age>30 then 'too old'
- else 'OK'
- end as status
- from person;
4.随机返回有限的(非全部)查询结果- select * from person order by rand() limit 1;
5.将null值显示为其他值- select id,coalesce(name,'No Name'),age from person;
6.对查询结果进行多关键字排序- select empno,deptno,sal,ename,job
- from emp
- order by deptno, sal desc
7.如果某个字段不存在于另一个表中,找出他- 1 select deptno
- 2 from dept
- 3 where deptno not in (select deptno from emp )
发表于 @ 2008年09月08日 17:34:00|评论(loading...)|收藏