时间:2022-07-08 10:28:38 | 栏目:MsSql | 点击:次
SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC, OrderNumber ASC #ASC升序,DESC倒序
1.以指定顺序返回查询结果(order by的asc为升序,desc为降序)
select ename,job,sal from emp where deptno = 10 order by sal asc
2.多字段排序
select empno,deptno,sal,ename,job from emp order by deptno,sal desc
3.依据子串排序(SQL Sever使用substring(),其它用substr,而substr只有两个参数)
select ename,job from emp order by substring(job,len(job)-2,2)
4.排序时对null值处理
select ename,job,comm from emp order by 3
5.依据条件逻辑动态调整排序项
select ename,sal,job,comm from emp order by case when job = ‘SALESMAN' then comm else sal end