sql查询按照in语句的顺序返回结果

sqlite写法

SELECT * FROM example WHERE id IN('4','3','2','1') ORDER BY INSTR('4,3,2,1',id);

mysql写法

SELECT * FROM example WHERE id IN(4,3,2,1) ORDER BY INSTR(',4,3,2,1,',CONCAT(',',id,','));

oracle写法

select name from example where id in4,3,2,1order by instr('4,3,2,1',id);

sqlserver写法

Select * From example Where id in (4,3,2,1)  Order By charindex(','+ id +',', ',4,3,2,1,');

本文作者:vanxkr

本文链接:http://www.vanxkr.com/2019/4/sql-in-orderby

版权声明:本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0许可协议。转载请注明出处!

Sqlite3 笔记
0 条评论
已登录,注销 取消