oracle

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系列:(7)order by子句

标签:oracle

原文:http://lsieun.blog.51cto.com/9210464/1847064

( 0)
( 0)
    
举报
评论 一句话评论(0
0条  
登录后才能评论! 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324812759&siteId=291194637