开发者

split row in mysql check for values in between

开发者 https://www.devze.com 2023-03-12 01:19 出处:网络
I have a column with a bunch of rows with values like this. ZIP -------- Value 010-212--8 214-268-- 9 270-324--7

I have a column with a bunch of rows with values like this.

ZIP -------- Value

010-212 -- 8

214-268 -- 9

270-324 -- 7

I am submitting a value like 245 to mysql and trying to figure out a way to grab the associated number, which would be 9 in this case.

How would I go about wri开发者_开发技巧ting a mysql statement and being able to tell if the number was in-between the two values in the zip row, for this example in-between and including 214-268 then use that to grab the associated value which is 9?

I feel as if I have to use SUBSTRING some how but am not sure how to go about writing it.

Any ideas?


Just for your knowledge

select value from table
where 245 
between 
substring_index(zip,'-',1)
and
substring_index(zip,'-',-1)

I totally agree with James' advice.

0

精彩评论

暂无评论...
验证码 换一张
取 消