MySQL - 在多列中排序特定的字段值

问题描述 投票:0回答:1

我有桌子

+-----------+------------+------+------+------+
| id        | name       | col1 |col2  | col3 |
+-----------+------------+------+------+------+

我想订购我的桌子有两个列,如(col1, col2) in (v1,v1),(v2,v2)...和其他一些订单。

MySQLORDER BY FIELD(col1, 'v1', 'v2', 'v3') DESC, other columns ASC;,但如何在多列中使用它像我的例子谢谢。

mysql sql-order-by
1个回答
1
投票

您可以连接字符串。

ORDER BY FIELD(CONCAT(col1, ',', col2), 'v1,v1', 'v2,v2', ...)
© www.soinside.com 2019 - 2024. All rights reserved.