简体   繁体   English

如何按任意顺序按列对行进行排序? MySQL数据库

[英]How to order rows by columns at arbitrary order ? MYSQL

I have this query : $query = "SELECT * FROM table1 ONE ORDER BY ....: 我有这个查询:$ query =“ SELECT * FROM table1 ONE ORDER BY ....:

the order should be in this way : 订单应采用以下方式:

  1. first the mysql should get the rows with status 2. 首先,mysql应该获得状态为2的行。
  2. then get the row with status 1. 然后获得状态为1的行。
  3. then get the row with status 3. 然后获得状态为3的行。

**status is a col at table1. **状态是表1的列。

像这样使用FIELD函数

 $query = "SELECT * FROM table1 ONE ORDER BY FIELD(status, 2, 1, 3)";

You can use conditionals in the order by . 您可以按order by使用条件。 Here is one method: 这是一种方法:

order by field(status, 2, 1, 3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM