两个字符串之间的MySQL查询有时不起作用 [英] MySql query BETWEEN two Strings sometimes doesn't work

查看:85
本文介绍了两个字符串之间的MySQL查询有时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mysql查询,其中一个子查询是:

I have a mysql query where a subquery is:

BETWEEN '5.00' AND '10.00' 

这将不返回任何结果.

And this returns no results.

但是,当我使用浮点数或整数时:

However when I use Floats or Ints:

BETWEEN 5 and 10 

有效

BETWEEN查询也可用于其他值AS字符串,但不适用于5和10.

The BETWEEN query also works for other values AS strings, but just not for 5 and 10.

EG:

BETWEEN '4' AND '5' 

有效.

怎么可能?

推荐答案

字符串和整数之间有区别-原因是您有几种不同的数据类型:

There is a difference between strings and integers -- there is a reason why you have several different datatypes :

比较整数时,是在比较它们的数值;即10大于5.

When comparing integers, you are comparing their numerical values ; i.e. 10 is bigger than 5.

比较字符串时,您使用的是字母比较;即'10'小于'5',因为'1'小于'5'.

When comparing strings, you are using an alphabetical comparison ; i.e. '10' is smaller than '5', because '1' is smaller than '5'.

这篇关于两个字符串之间的MySQL查询有时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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