06-Oracle入门之order by排序
发布时间:2020-12-12 15:28:40 所属栏目:百科 来源:网络整理
导读:ORDER BY子句 使用 ORDER BY 子句排序 ASC(ascend): 升序 DESC(descend): 降序 ORDER BY 子句在SELECT语句的结尾。 order by后面+ 列名、 表达式 、别名 、序号 一般套路 SELECT last_name,job_id,department_id,hire_date FROM employees ORDER BY hire
ORDER BY子句
SELECT last_name,job_id,department_id,hire_date FROM employees ORDER BY hire_date ;
select ....
from ...
where ...
order by ...
升序排列默认就是升序! 1 select *
2 from emp
3* order by sal asc
SQL> /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-12月-80 800 20
7900 JAMES CLERK 7698 03-12月-81 950 30
7876 ADAMS CLERK 7788 23-5月 -87 1100 20
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7934 MILLER CLERK 7782 23-1月 -82 1300 10
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7782 CLARK MANAGER 7839 09-6月 -81 2450 10
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7788 SCOTT ANALYST 7566 19-4月 -87 3000 20
7902 FORD ANALYST 7566 03-12月-81 3000 20
7839 KING PRESIDENT 17-11月-81 5000 10
降序排列SELECT last_name,hire_date FROM employees ORDER BY hire_date DESC ;
多个列排序
select * from emp order by deptno asc,sal asc
select * from emp order by deptno asc,sal desc
别名排序SQL> ed
Wrote file afiedt.buf
1 select ename,empno,sal*12 sal_sum
2 from emp
3* order by sal_sum
SQL> /
排序的规则
排序中的空值排序的时,如何将null排在最后. select * from emp order by comm desc nulls last;
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |