Mysql:在两列之间选择值 [英] Mysql: Selecting values between two columns
本文介绍了Mysql:在两列之间选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在2列之间选择一个值.这是我的数据集
I'm trying to select a value between 2 columns. Here is my dataset
id from to price
1 0.00 2.00 2.50
2 2.00 3.00 3.00
3 3.00 4.00 4.50
如果我的值为2,则我的目标是选择 ID 1 (从and到之间)的行.所以这是我正在使用的查询:
My goal, if I have a value of 2 is to select the line with the ID 1 (between from and to). So here is the query I'm using :
select * from table where 2 between from and to;
这是MySQL执行此查询时返回的结果:
And here are the results that MySQL returns when executing this query :
id from to price
1 0.00 2.00 2.50
2 2.00 3.00 3.00
我正在寻找的结果如下:
And the result I'm looking for is the following :
id from to price
1 0.00 2.00 2.50
我尝试使用<和>等.但是,我总是得到两个结果.任何帮助将不胜感激.
I've tried using < and >, etc. But, I'm always getting two results. Any help would be much appreciated.
推荐答案
所以,您不希望将下限包含在内,对吗?
SO, you don't want the lower bound to be inclusive, right?
SET @value = 2;
SELECT * FROM table WHERE from > @value AND @value <= to;
这篇关于Mysql:在两列之间选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文