订购MySQL数据

小咪咪 2022-12-06 15:24 195阅读 0赞

When you query a MySQL database, you can sort the results by any field in an ascending or descending order just by adding ORDER BY at the end of your query. You use ORDER BY field_name ASC for an ascending sort (which is the default) or ORDER BY field_name DESC for a descending sort. You can use an ORDER BY clause in a SELECT statement, SELECT LIMIT or DELETE LIMIT statement. For example:

查询MySQL数据库时 ,只需在查询末尾添加ORDER BY,就可以按任何字段以升序或降序对结果进行排序。 您可以使用ORDER BY field_name ASC进行升序排序(这是默认设置),或使用ORDER BY field_name DESC进行降序排序。 您可以在SELECT语句,SELECT LIMIT或DELETE LIMIT语句中使用ORDER BY子句。 例如:

  1. SELECT *
  2. FROM address
  3. ORDER BY name ASC;

The code above retrieves data from an address book and sorts the results by the person’s name in an ascending fashion.

上面的代码从通讯录中检索数据,并以人的名字升序对结果进行排序。

  1. SELECT email
  2. FROM address
  3. ORDER BY email DESC;

This code selects only the email addresses and lists them in descending order.

此代码仅选择电子邮件地址,并按降序列出。

Note: If you don’t use an ASC or DESC modifier in the ORDER BY clause, the data is sorted by expression in ascending order, which is the same as specifying ORDER BY expression ASC.

注意:如果未在ORDER BY子句中使用ASC或DESC修饰符,则数据按表达式升序排序,这与指定ORDER BY表达式ASC相同。

翻译自: https://www.thoughtco.com/ordering-mysql-data-2693870

发表评论

表情:
评论列表 (有 0 条评论,195人围观)

还没有评论,来说两句吧...

相关阅读