sql 中按字母顺序排序
在 SQL 中,可以使用 ORDER BY 子句对结果集中的数据按字母顺序进行排序。
语法:
SELECT 列名 FROM 表名 ORDER BY 列名 ASC/DESC;
参数:
-
列名:要按其排序的列 -
ASC:按升序排序(从小到大) -
DESC:按降序排序(从大到小)
示例:
按升序对 customers 表中的 name 列排序:
SELECT name FROM customers ORDER BY name ASC;
按降序对 orders 表中的 order_date 列排序:
SELECT order_date FROM orders ORDER BY order_date DESC;
注意:
- 默认情况下,
ORDER BY子句按升序排序。 -
如果要对多个列排序,可以使用逗号将列名分开。例如:
ORDER BY name ASC, age DESC;










