mysql in 默认的排序select id from table where id in (2,1,3,5);查出来的结果是:1 2 3 5但是有的时候是要:2 1 3 5这就需要做排序的时候做处理,网上有2种方法,但是没有详细的解释。查了下手册,记下方便自己以后查找。1. select id from table where id in (2,1,3,5) order by substring_index('2,1,3,5',id,1);substring_index(str,delim,count) 字符串截取函数str 要截取的字符串 delim 截取的分割符 count 截取的数量返回从字符串str的第count个出现的分隔符delim之后的子串。如果count是正数,返回最后的分隔符到左边(从左边
发布时间:
2012-03-23 |
类别:
技术文章 | 阅读:267382 | 评论:0 |
标签:
in in