MYSQL – 指定排序

+—-+——-+
| id | name |
+—-+——-+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
| 5 | test5 |
+—-+——-+
//須要取得id 為指定數字時並依照排序的兩種方法

select * from test where id in(3,1,5) order by find_in_set(id,’3,1,5′);

select * from test where id in(3,1,5) order by substring_index(‘3,1,2’,id,1);


發表迴響