mysql id in 排列问题
来源:互联网 发布:c语言函数调用的例子 编辑:程序博客网 时间:2024/04/28 06:37
SELECT * FROM szmg0112.cms_archives c where id in(13934,13914,13915,13923,13910,13891,13920,13882,13937,13924,13881) order by substring_index('13934,13914,13915,13923,13910,13891,13920,13882,13937,13924,13881',id,1)
语句可以根据id里面的顺序来排列查询。
select id from table where id in (2,1,3,5) order by field(id,2,1,3,5)
mysql in 默认的排序
select id from table where id in (2,1,3,5);
查出来的结果是:1 2 3 5
但是有的时候是要:2 1 3 5
这就需要做排序的时候做处理,网上有2种方法,但是没有详细的解释。查了下手册,记下方便自己以后查找。
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是正数,返回最后的分隔符到左边(从左边数) 的所有字符。如果count是负数,返回最后的分隔符到右边的所有字符(从右边数)。
那 order by substring_index(‘2,1,3,5′,id,1) 这个啥意思呢
这个是在字符串’2,1,3,5′里查找id,如果找不到,就返回整个字符串
select id from table where id in (2,1,3,5) order by find_inset(id,'2,1,3,5')find_in_set(str,strlist) 字符串函数如果字符串str在由N子串组成的表strlist之中,返回一个1到N的值。如果str不是在strlist里面或如果strlist是空字符串,返回0。SELECT FIND_IN_SET('b','a,b,c,d'); -> 2所以 find_in_set返回的是一个1到N的值,在order by的话,就是按顺序排了。
- mysql id in 排列问题
- Mysql 中 查询结果顺序按 IN 关键字中ID 的排列
- MySQL 存储过程传参数问题:实现 where id in(1,2,3,...)
- MySQL 存储过程传参数问题:实现 where id in(1,2,3,...)
- mysql升序排列id为0的在最后
- mysql in根据查询id排序
- mysql in根据查询id排序
- mysql查询ID排序问题,
- sql select id in的排序问题
- mysql IN的问题
- Mysql "in" 排序问题
- Mysql In 排序问题
- UVa146 ID Codes (排列)
- Mysql select in 按id排序实现方法
- (转)mysql in根据查询id排序
- MySQL 查询 select * from table where id in 如何提高效率?
- Mysql查询结果顺序按 in() 中ID 的顺序排列
- Mysql查询结果顺序按 in() 中ID 的顺序排列
- 指针和引用的区别
- Oracle to_char格式化函数
- [Android] 获得所有的Sensor信息
- Oracle扫描工具 By open
- python+pygame 生成迷宫
- mysql id in 排列问题
- ITU-R BT.601 介绍(转)
- 用监听器来实现网络在线人数
- 关于IE6的css文件
- SD/MMC SPI模式下命令合集
- 编写一个程序 输入字符串 直到遇到NULL 实现字符串的首字母排序(图)
- metalink--Oracle的官方技术支持站点
- 20120603晴,户外摄影
- iphone 相关文件名含义