mysql使用in查询,按照期望的顺序输出结果
2015-12-31 11:42
846 查看
mysql使用in查询,按照期望的顺序输出结果,可以使用field函数
结果:
MySQL FIELD() returns the index position of the searching string from a list of strings. If search string is not found, it returns a 0(zero). If search string is NULL, the return value is 0 because
NULL fails equality comparison with any value.
FIELD() is the complement of ELT(). When all arguments of the FIELD() are strings, they are compared as strings. If all arguments are number, they compared as numbers. Other wise all are compared as double.
SELECT ProvinceId, ProvinceName FROM btoc_province WHERE ProvinceName IN ('河南', '辽宁', '山西') ORDER BY FIELD( provincename, '河南', '辽宁', '山西' );
结果:
MySQL FIELD() function
MySQL FIELD() returns the index position of the searching string from a list of strings. If search string is not found, it returns a 0(zero). If search string is NULL, the return value is 0 becauseNULL fails equality comparison with any value.
FIELD() is the complement of ELT(). When all arguments of the FIELD() are strings, they are compared as strings. If all arguments are number, they compared as numbers. Other wise all are compared as double.
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- PreparedStatement中in子句的处理
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜