查詢員工信息(編號,姓名,月薪,年薪),按月薪升序排序,默認升序,如果月薪相同,按oracle內置的校驗規則排序
select empno,ename,sal,sal*12 from emp order by sal asc;
查詢員工信息(編號,姓名,月薪,年薪),按月薪降序排序
select empno,ename,sal,sal*12 from emp order by sal desc;
查詢員工信息,按入職日期降序排序,使用列名
select empno,ename,sal,hiredate,sal*12 "年薪" from emp order by hiredate desc;
order by后面可以跟列名、別名、表達式、列號(從1開始,在select子句中的列號)
列名:
select empno,ename,sal,hiredate,sal*12 "年薪" from emp order by hiredate desc;
別名:
select empno,ename,sal,hiredate,sal*12 "年薪" from emp order by "年薪" desc;
表達式:
select empno,ename,sal,hiredate,sal*12 "年薪" from emp order by sal*12 desc;
列號,從1開始:
select empno,ename,sal,hiredate,sal*12 "年薪" from emp order by 5 desc;

查詢員工信息,按傭金升序或降序排列,null值看成最大值
select * from emp order by comm desc;


查詢員工信息,對有傭金的員工,按傭金降序排列,當order by 和 where 同時出現時,order by 在最后
select * from emp where comm is not null order by comm desc;

查詢員工信息,按工資降序排列,相同工資的員工再按入職時間降序排列
select * from emp order by sal desc,hiredate desc;
select * from emp order by sal desc,hiredate asc;
注意:只有當sal相同的情況下,hiredate排序才有作用
查詢20號部門,且工資大于1500,按入職時間降序排列
select * from emp where (deptno=20) and (sal>1500) order by hiredate desc;

下面的字符串'30'可以隱式轉換為數字
select * from emp where deptno in (10,20,30,50,'30');

select * from emp where deptno in (10,20,30,50,'a');

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。