SUBSTRING_INDEX(str,delim,count)
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
-> 'www.mysql'
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
-> 'mysql.com'
以下sql用法是转载:
这个select在mysql中得结果会自动按照id升序排列,
但是我想执行"select * from test where id in(3,1,5);"的结果按照in中得条件排序,即:3,1,5,
想得到的结果如下:
id name
3 test3
1 test1
5 test5
请问在这样的SQL在Mysql中怎么写?
网上查到sqlserver中可以用order by charindex解决,但是没看到Mysql怎么解决??请高手帮忙,谢
谢!
select * from a order by substring_index('3,1,2',id,1);
试下这个good,ls正解。
order by find_in_set(id,'3,1,5')
谢谢,经测试order by substring_index和order by find_in_set都可以