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;
新闻热点
疑难解答