SQL循序渐进(13)ORDER BY子句
ORDER BY子句 ORDER BY子句的语法为: SELECT column1, SUM(column2) FROM "list-of-tables" ORDER BY "column-list" [ASC | DESC]; [ ] = optional ORDER BY是一个可选的子句,它允许你根据指定要order by的列来以上升或者下降的顺序来显示查询的结果。例如
ORDER BY子句
ORDER BY子句的语法为:
SELECT column1, SUM(column2)
FROM "list-of-tables"
ORDER BY "column-list" [ASC | DESC];
[ ] = optional
ORDER BY是一个可选的子句,它允许你根据指定要order by的列来以上升或者下降的顺序来显示查询的结果。例如:
ASC = Ascending Order – 这个是缺省的
DESC = Descending Order
下面举个例子:
SELECT employee_id, dept, name, age, salary
FROM employee_info
WHERE dept = 'Sales'
ORDER BY salary;
这条
SQL语句将从employee_info表中列dept等于'Sales'选择employee_id,、dept、 name、 age和 salary,并且根据他们的salary按升序的顺序来列出检索结果。
如果你想对多列排序的话,那么在列与列之间要加上逗号,比如 :
SELECT employee_id, dept, name, age, salary
FROM employee_info
WHERE dept = 'Sales'
ORDER BY salary, age DESC;
原文转自:http://www.ltesting.net
|