Query employee information (number, name, monthly salary, annual salary), sort by monthly salary in ascending order, the default ascending order, if the monthly salary is the same, sort by oracle built-in check rules
select empno,ename,sal,sal*12 from emp order by sal asc;
Query employee information (number, name, monthly salary, annual salary), sort by monthly salary in descending order
select empno,ename,sal,sal*12 from emp order by sal desc;
Query employee information, sort by entry date in descending order, using column names
select empno,ename,sal,hiredate,sal*12 "Annual Salary" from emp order by hiredate desc;
order by can be followed by column name, alias, expression, column number (starting from 1, the column number in the select clause)
Column name:
select empno,ename,sal,hiredate,sal*12 "Annual Salary" from emp order by hiredate desc;
Alias:
select empno,ename,sal,hiredate,sal*12 "Annual Salary" from emp order by "Annual Salary" desc;
expression:
select empno,ename,sal,hiredate,sal*12 "Annual Salary" from emp order by sal*12 desc;
Column number, starting from 1:
select empno,ename,sal,hiredate,sal*12 "Annual Salary" from emp order by 5 desc;
Query employee information, sort by commission in ascending or descending order, null value is regarded as the maximum value
select * from emp order by comm desc;
Query employee information. For employees with commissions, they are sorted in descending order by commission. When order by and where appear at the same time, order by is at the end.
select * from emp where comm is not null order by comm desc;
Query employee information, sort in descending order of salary, and then sort employees with the same salary in descending order of entry time
select * from emp order by sal desc,hiredate desc;
select * from emp order by sal desc, hiredate asc;
Note: hiredate sorting only works if the sal is the same
Query the No. 20 department, and the salary is greater than 1500, in descending order of entry time
select * from emp where (deptno=20) and (sal>1500) order by hiredate desc;
The string '30' below can be implicitly converted to a number
select * from emp where deptno in (10,20,30,50,‘30‘);
select * from emp where deptno in (10,20,30,50,‘a‘);
标签:oracle
原文:http://lsieun.blog.51cto.com/9210464/1847064