来自 热门技术 2018-11-24 10:47 的文章

根据条件取不同列中的值来排序,条件排序

根据条件取不同列中的值来排序,条件排序

有时排序的要求会比较复杂,比如:领导对工资在1000到2000元之间的员工更感兴趣,于是要求工资在这个范围的员工要排在前面,以便优先查看。

创建测试用表:

CREATE OR REPLACE VIEW v AS
鼎盛娱乐SELECT 'MARTIN' AS ename, 950 AS sal FROM DUAL
UNION ALL
SELECT 'WERD' AS ename, 1250 AS sal FROM DUAL
UNION ALL
SELECT 'TERNER' AS ename, 1500 AS sal FROM DUAL
UNION ALL
SELECT 'ALLEN' AS ename, 1600 AS sal FROM DUAL
UNION ALL
SELECT 'JAMES' AS ename, 2850 AS sal FROM DUAL;
SELECT * FROM v;

sql代码如下:

SELECT * FROM v ORDER BY CASE WHEN sal BETWEEN 1000 AND 2000 THEN 1 ELSE 2 END, sal;

执行结果如下:

http://www.bkjia.com/oracle/1060228.htmlwww.bkjia.comtruehttp://www.bkjia.com/oracle/1060228.htmlTechArticle根据条件取不同列中的值来排序,条件排序 有时排序的要求会比较复杂,比如:领导对工资在1000到2000元之间的员工更感兴趣,于是要求工...

本文源自: AG88平台