7.ORDER BY 子句
ORDER BY 语句
ORDER BY 语句用于根据指定的列对结果集进行排序。
ORDER BY 语句默认按照升序对记录进行排序。
如果您希望按照降序对记录进行排序,可以使用 DESC 关键字。
1.以时间显示,升序
mysql> select * from Orders order by OrderDate;
+------+------------+------------+----------+
| O_Id | OrderDate | OrderPrice | Customer |
+------+------------+------------+----------+
| 1 | 2008-07-22 | 1000.00 | Carter |
| 6 | 2008-11-22 | 1000.00 | Adams |
| 5 | 2008-11-29 | 1000.00 | Bush |
| 2 | 2008-12-24 | 1000.00 | Bush |
| 3 | 2008-12-26 | 1000.00 | tom |
| 4 | 2008-12-27 | 1000.00 | Carter |
| 1 | 2008-12-29 | 1000.00 | Bush |
+------+------------+------------+----------+
7 rows in set (0.04 sec)
2.以字母顺序显示Customer名称,并以数字顺序显示顺序号(OrderDate):
mysql> select * from Orders order by Customer,OrderDate;
+------+------------+------------+----------+
| O_Id | OrderDate | OrderPrice | Customer |
+------+------------+------------+----------+
| 6 | 2008-11-22 | 1000.00 | Adams |
| 5 | 2008-11-29 | 1000.00 | Bush |
| 2 | 2008-12-24 | 1000.00 | Bush |
| 1 | 2008-12-29 | 1000.00 | Bush |
| 1 | 2008-07-22 | 1000.00 | Carter |
| 4 | 2008-12-27 | 1000.00 | Carter |
| 3 | 2008-12-26 | 1000.00 | tom |
+------+------------+------------+----------+
7 rows in set (0.00 sec)
3.以逆字母顺序显示Customer名称:
mysql> select * from Orders order by Customer desc ;
+------+------------+------------+----------+
| O_Id | OrderDate | OrderPrice | Customer |
+------+------------+------------+----------+
| 3 | 2008-12-26 | 1000.00 | tom |
| 1 | 2008-07-22 | 1000.00 | Carter |
| 4 | 2008-12-27 | 1000.00 | Carter |
| 1 | 2008-12-29 | 1000.00 | Bush |
| 2 | 2008-12-24 | 1000.00 | Bush |
| 5 | 2008-11-29 | 1000.00 | Bush |
| 6 | 2008-11-22 | 1000.00 | Adams |
+------+------------+------------+----------+
7 rows in set (0.00 sec)
4.以逆字母顺序显示Customer名称,并以数字顺序显示顺序号OrderDate:
mysql> select * from Orders order by Customer desc, OrderDate asc ;
+------+------------+------------+----------+
| O_Id | OrderDate | OrderPrice | Customer |
+------+------------+------------+----------+
| 3 | 2008-12-26 | 1000.00 | tom |
| 1 | 2008-07-22 | 1000.00 | Carter |
| 4 | 2008-12-27 | 1000.00 | Carter |
| 5 | 2008-11-29 | 1000.00 | Bush |
| 2 | 2008-12-24 | 1000.00 | Bush |
| 1 | 2008-12-29 | 1000.00 | Bush |
| 6 | 2008-11-22 | 1000.00 | Adams |
+------+------------+------------+----------+
7 rows in set (0.00 sec)
7.ORDER BY 子句的更多相关文章
- TSQL order by 子句中排序列的多种写法
Order by 子句用于对结果进行排序,执行顺序位于select子句之后,排序列有4中写法: column_name column_alias,由于order by子句的执行顺序位于select子句 ...
- sql:除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询
执行sql语句: select * from ( select * from tab where ID>20 order by userID desc ) as a order by date ...
- T-SQL ORDER BY子句 排序方式
MS SQL Server ORDER BY子句用于根据一个或多个列以升序或降序对数据进行排序. 默认情况下,一些数据库排序查询结果按升序排列. 语法 以下是ORDER BY子句的基本语法. SELE ...
- ORDER BY 子句在视 图、内联函数、派生表、子查询和公用表表达式中无效
SQL语句: select * from (select distinct t2.issue,cashmoney from (select distinct issue from lot_gamepa ...
- 1. 安装Oracle,配置环境 2. 实现查询From子句 3. 实现查询where子句 4. 实现查询order by子句
一.环境安装1. 登录:以管理员身份登录 sqlplus 登录名/密码 管理员身份登录:sqlplus system/1234562. 登录后,导入案例.下载scott.sql文件,执行下面一行的命令 ...
- [转]sql:除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询
执行sql语句: select * from ( select * from tab where ID>20 order by userID desc ) as a order by date ...
- MySQL的order by子句
1.语法:select 字段列表 from 表名 [where 子句][group by 子句][having 子句][order by 子句]; 注解: 1.默认是从第一条记录开始升序, 2.des ...
- [sql Server]除非另外还指定了TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效
今天遇到一个奇怪的问题,项目突然要从mysql切换到sql server数据库,包含order by 子句的嵌套子查询报错. 示例:select top 10 name,age,sex from ( ...
- Mysql查询语句的 where子句、group by子句、having子句、order by子句、limit子句
Mysql的各个查询语句 一.where子句 语法:select *|字段列表 from 表名 where 表达式.where子句后面往往配合MySQL运算符一起使用(做条件判断) 作用:通过限定 ...
- MySQL中列别名为中文时,Order by 子句中使用别名时不要加引号
暂时还不清楚原因 1.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩 SC表: 这里,当做总成绩处理 select sid, sum(score) as '总成绩', avg(score) ...
随机推荐
- test20181219(期末考试)
Written with StackEdit. \(noip\)爆炸后就好久没考试了...结果今天又被抓去,感觉很慌啊... 考完了.过来填坑. T1 Description 使得\(x^x\)达到或 ...
- jquery ajax 跨域设置
xhrFields: { withCredentials: true},crossDomain: true,
- js插件大全 jquery插件大全
CocoaUI - 一个强大的 iOS UI 框架 http://www.cocoaui.com/ tab,slider,轮播不错的说 http://www.superslide2.com/index ...
- 12C 新特性--全库缓存
Force Full Database Caching Mode 意思就是可以把整个数据库缓存到内存中,当然你内存一定要非常大,起码要等于数据库的大小,才能容下整个数据库. 在RAC环境下,对于一个良 ...
- 自制html
//$this->_red('账号或密码有误','/student/stureg/add'); echo '<meta http-equiv="Content-Type" ...
- spring-cloud配置eureka客户端
spring-cloud配置eureka客户端 eureka用来发现其他程序 需要提前配置eureka服务端,具体看 https://www.cnblogs.com/ye-hcj/p/10292944 ...
- mysql int类型范围
int范围 Type Bytes Minimum Value Maximum Value (Signed/Unsigned) (Signed/Unsigned) TINYINT 1 -128 ...
- Aptana Studio 3 如何汉化,实现简体中文版
这篇文章写了又一年多的时间了,哈哈,今天更新一次 此处修正的下面教程的[第五步]Babel Language Pack Update Site for Helioshttp://download.ec ...
- Deep Learning(深度学习)学习笔记整理系列
http://blog.csdn.net/zouxy09/article/details/8775360 http://blog.csdn.net/zouxy09/article/details/87 ...
- leetcode693
class Solution { public: bool hasAlternatingBits(int n) { ; while (n) { ; ) { last = x; } else { if ...