希望结果与传递给IN条件的顺序相同:
SELECT * FROM `table_x` WHERE `id` IN (30, 12, 1001, 24);
获得:
id | field_a | field_b -------------------------- 12 | ... | ... 24 | ... | ... 30 | ... | ... 1001 | ... | ...
期待:
id | field_a | field_b -------------------------- 30 | ... | ... 12 | ... | ... 1001 | ... | ... 24 | ... | ...
答案 0 :(得分:2)
SELECT * FROM `table_x`
WHERE `id` IN (30, 12, 1001, 24)
order by field(id, 30, 12, 1001, 24)
答案 1 :(得分:1)