让sql语句不排序,按照in语句的顺序返回结果
2016-10-28 16:08
323 查看
有时候我们需要按照in条件里的id顺序输出结果,可sql语句在不加order by的时候是按照asc排序的,下边的sql解决按照in条件顺序的id输出查询结果
MySQL写法:
SELECT * FROM EVENT WHERE eventId IN(443,419,431,440,420,414,509) ORDER BY INSTR(‘,443,419,431,440,420,414,509,’,CONCAT(‘,’,eventId,’,’))
或者
select * from EVENT where eventId IN (3,6,9,1,2,5,8,7) order by field(eventId ,3,6,9,1,2,5,8,7);
Oracle写法:
select name from order where oderid in(111,222,333,444,555,666)order by instr(‘111,222,333,444,555,666’,orderid)
或者
select status from BUS_ROW_NUMBER order by DECODE(status , ‘01’,’1’,’02’,’2’,’03’,’3’)
sqlserver写法:
Select * From Product Where id in (1,1588,15782,9887,54) Order By charindex(‘,’+ id +’,’, ‘,1,1588,15782,9887,54,’)
MySQL写法:
SELECT * FROM EVENT WHERE eventId IN(443,419,431,440,420,414,509) ORDER BY INSTR(‘,443,419,431,440,420,414,509,’,CONCAT(‘,’,eventId,’,’))
或者
select * from EVENT where eventId IN (3,6,9,1,2,5,8,7) order by field(eventId ,3,6,9,1,2,5,8,7);
Oracle写法:
select name from order where oderid in(111,222,333,444,555,666)order by instr(‘111,222,333,444,555,666’,orderid)
或者
select status from BUS_ROW_NUMBER order by DECODE(status , ‘01’,’1’,’02’,’2’,’03’,’3’)
sqlserver写法:
Select * From Product Where id in (1,1588,15782,9887,54) Order By charindex(‘,’+ id +’,’, ‘,1,1588,15782,9887,54,’)
相关文章推荐
- 如何让SQL语句不执行默认排序,而是按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果mysql:SELECT*FROMEVENTWHER
- 让sql语句不排序,按照in语句的顺序返回结果
- 让sql语句结果集不排序,按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果
- sql语句 不让得出的结果默认排序,让其按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果
- sql语句 不让结果排序,按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果
- SQL按照in语句的顺序返回结果
- SQL 语句中按照in语句原有的顺序进行排序
- [导入]实现SQL语句中,按照in 中的顺序排序的方法
- SQL 语句中按照in语句原有的顺序进行排序
- SQL 语句中按照in语句原有的顺序进行排序
- mybatis如何直接 执行传入的任意sql语句 并按照顺序取出查询的结果集
- sql 语句按照汉字顺序排序