mysql中对order by的函数substring_index() , find_in_set()使用,
分享于 点击 27074 次 点评:198
mysql中对order by的函数substring_index() , find_in_set()使用,
其实今天写这个博文完全是因为面试中遇到的了,呵呵了吧
题目是这样的:sql = "select * from table where id in(3,1,2,5)"; 怎样使得查询的结果按照 3 ,1 , 2, 5来排序;
答案:这两个SQL函数在平时真心没用使用到过啊 find_in_set() 和 substring_index()
用法是这样:
select * from table order by substring_index('3,1,2,5',id,1);
select * from table order by find_in_set(id,'3,1,5')
相关文章
- 暂无相关文章
用户点评