我有一个表“book_history”,其中包含一个字段“status”
So there are three values for the field 'status' => 0,1,2
现在我想按 orderby 查询它 - 我知道 order by asc 和 order by desc 在那里。 但我真正想要的是
select * from book_history order by status 1,0,2
那时我也检查了订单。但是我无法进行查询。
所以最终的输出将是 - 首先它应该列出 status=1,然后是 status=0,然后是 status='2'
任何帮助。
谢谢,
金兹
最佳答案
您可以使用 FIELD()功能
SELECT
*
FROM
book_history
ORDER BY FIELD(`status`, 1, 0, 2)
关于php - 在没有asc和desc的mysql中排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23510721/