SQL - 在varchar列之间的WHERE

时间:2015-10-13 10:58:37

标签: sql where between

我有一个表company,其中包含customerID列,我希望每个客户ID都在80000到80999之间。

但是customerID列是varchar,其中一些包含字母。

所以,我必须将customerID放入' '当我尝试这个查询时:

select *
from company
where customerID between '80000' and '80999'

例如,它还返回customerID 800。

有关如何解决此问题的任何想法?

3 个答案:

答案 0 :(得分:0)

您可以使用正则表达式进行格式化。这样的事情应该让你开始Query to get only numbers from a string

答案 1 :(得分:0)

where customerID between '80000' and '80999'
  and character_length(customerID) = 5 -- only five digit IDs

答案 2 :(得分:0)

如果CustomerID是一个整数,它应该是,你不需要围绕numnbers的引号。它应该解决问题:

select *
from company
where customerID between 80000 and 80999;