如何在MySQL中的BETWEEN子句中使用字母数字字段? [英] How to use alphanumeric fields with BETWEEN clause in Mysql?

查看:423
本文介绍了如何在MySQL中的BETWEEN子句中使用字母数字字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中包含一个名为mgrs的字段名称,存储在mgrs字段中的值就像'42SWC227821555'可能包含更多字符,并且可能包含小写字母.所以现在我要搜索两个mgrs之间的记录,那么我该怎么做?我可以先将mgrs值转换为整数,然后在between子句中使用吗?

I have a table that contain a field names as mgrs, the value that stored in mgrs fields is like '42SWC227821555' may contain more charachters, and may contain lower case letters. So now i want to search records between two mgrs, so how can i do that? can i convert mgrs value to integer first and then use in between clause?

推荐答案

使用BETWEEN子句-functions.html#function_strcmp"rel =" nofollow> STRCMP(expr1, expr2) 用于字符串比较操作的函数:

Instead of BETWEEN clause use STRCMP(expr1, expr2) function for string comparison operations:

WHERE STRCMP(mgrs, '42SWC227821555') >= 0 AND STRCMP(mgrs, '42SWC227821570') <= 0

这篇关于如何在MySQL中的BETWEEN子句中使用字母数字字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆