功能介绍:
可以指定排序字段和排序方向,使查询结果按一定的顺序展现
语法描述:
SELECT select_list
FROM T
WHERE search_condition
ORDER BY order_expression[ ASC | DESC ], ......
参数说明:
order_expression |
排序字段或者排序表达式 |
ASC |
升序 |
DESC |
降序 |
举例:
SELECT OrderID,CustomerID,EmployeeID,ReceiveDate,ShipDate,Amount FROM Orders ORDER BY Amount DESC |
根据Amount降序排序 |
SELECT OrderID,CustomerID,EmployeeID,ReceiveDate,ShipDate,Amount FROM Orders ORDER BY EmployeeID |
不指定升降序,默认为升序;根据EmployeeID升序排序 |
SELECT EmpID,Name,Title,age(BirthDate) Age,HireDate,Boss,HomeCity FROM Employee ORDER BY Age DESC,HireDate ASC |
按年龄先降序,再按入职日期升序 |