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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理