Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要使用“IN”语句从我的数据库中选择用户,例如:
SELECT * FROM users WHERE user_id IN ("20,24,23,26,27,28,25")
...这有效,但我的输出需要这个顺序(20,24,23,26,27,28,25)。PHP 通过 DESC 或 ASC 对 id 进行排序……我该如何解决这个问题?
只FIELD()在ORDER BY子句中使用
FIELD()
ORDER BY
ORDER BY FIELD(user_id, 20, 24, 23, 26, 27, 28, 25) ASC