我需要以与IN(...)
clausule相同的顺序对结果进行排序。这该怎么做?例如:
SELECT id, name, desc FROM my_table WHERE id IN (8, 4, 19, 48, 15)
所以我需要按此顺序8, 4, 19, 48, 15
订购结果。
感谢。
答案 0 :(得分:0)
您可以使用order by field
WHERE id IN (8, 4, 19, 48, 15)
order by field(id,8, 4, 19, 48, 15);
答案 1 :(得分:-1)
您需要附加ORDER BY FIELD(id,7,5,3,1)
SELECT id, name, desc FROM my_table WHERE id IN (7,5,3,1) ORDER BY FIELD(id,7,5,3,1);