We used order by clause to sort rows in an order that you specify.
Sorting data is ascending order by .
1- Numeric data is sorted from the lowest to the highest number.
2- Character data is sorted alphabetically from A to Z .
3- Date data is sorted from the earliest to the latest date.
4- Null values are displayed last for ascending sequences.
You can use a column alias in an order by clause to sort information.
You can sort data by expression.
Examples
Select empno,ename,sal
From emp
Order by sal;
EMPNO ENAME SAL
------ ---------- ----------
7369 SMITH 800
7900 JAMES 950
7876 ADAMS 1100
7521 WARD 1250
7654 MARTIN 1250
7934 MILLER 1300
7844 TURNER 1500
7499 ALLEN 1600
7782 CLARK 2450
7698 BLAKE 2850
7566 JONES 2975
EMPNO ENAME SAL
------ ---------- ----------
7788 SCOTT 3000
7902 FORD 3000
7839 KING 5000
Select empno,ename,sal
From emp
Order by ename;
EMPNO ENAME SAL
------- ---------- ----------
7876 ADAMS 1100
7499 ALLEN 1600
7698 BLAKE 2850
7782 CLARK 2450
7902 FORD 3000
7900 JAMES 950
7566 JONES 2975
7839 KING 5000
7654 MARTIN 1250
7934 MILLER 1300
7788 SCOTT 3000
EMPNO ENAME SAL
------- ---------- ----------
7369 SMITH 800
7844 TURNER 1500
7521 WARD 1250
Select empno,ename,sal,hiredate
From emp
Order by hiredate;
EMPNO ENAME SAL HIREDATE
------ ---------- ---------- ---------
7369 SMITH 800 17-DEC-80
7499 ALLEN 1600 20-FEB-81
7521 WARD 1250 22-FEB-81
7566 JONES 2975 02-APR-81
7698 BLAKE 2850 01-MAY-81
7782 CLARK 2450 09-JUN-81
7844 TURNER 1500 08-SEP-81
7654 MARTIN 1250 28-SEP-81
7839 KING 5000 17-NOV-81
7900 JAMES 950 03-DEC-81
7902 FORD 3000 03-DEC-81
EMPNO ENAME SAL HIREDATE
------ ---------- ---------- ---------
7934 MILLER 1300 23-JAN-82
7788 SCOTT 3000 19-APR-87
7876 ADAMS 1100 23-MAY-87
Select empno,ename,sal,hiredate,sal*12
From emp
Order by sal*12;
EMPNO ENAME SAL HIREDATE SAL*12
------- ---------- ---------- --------- ----------
7369 SMITH 800 17-DEC-80 9600
7900 JAMES 950 03-DEC-81 11400
7876 ADAMS 1100 23-MAY-87 13200
7521 WARD 1250 22-FEB-81 15000
7654 MARTIN 1250 28-SEP-81 15000
7934 MILLER 1300 23-JAN-82 15600
7844 TURNER 1500 08-SEP-81 18000
7499 ALLEN 1600 20-FEB-81 19200
7782 CLARK 2450 09-JUN-81 29400
7698 BLAKE 2850 01-MAY-81 34200
7566 JONES 2975 02-APR-81 35700
EMPNO ENAME SAL HIREDATE SAL*12
------- ---------- ---------- --------- ----------
7788 SCOTT 3000 19-APR-87 36000
7902 FORD 3000 03-DEC-81 36000
No comments:
Post a Comment