[英]How to MySQL Between used for Higher value to Lower value?
Here I mentioned query: 在这里我提到了查询:
lowerValue = 3, upperValue = 6 lowerValue = 3,upperValue = 6
SELECT * FROM SampleTable where tableDay BETWEEN 'lowerValue' AND 'upperValue';
This query is working fine, but I need given below query type 此查询工作正常,但我需要在下面提供查询类型
lowerValue = 3, upperValue = 6 lowerValue = 3,upperValue = 6
SELECT * FROM SampleTable where tableDay BETWEEN 'upperValue' AND 'lowerValue';
It's return as empty list, because both values are dynamic, what I'm doing wrong? 它返回为空列表,因为两个值都是动态的,所以我做错了什么?
As a quickfix you could go with GREATEST() / LEAST() comparison functions: 作为一个快速修复,您可以使用GREATEST() / LEAST()比较函数:
SELECT *
FROM SampleTable
WHERE tableDay BETWEEN LEAST(upperValue, lowerValue) AND
GREATEST(upperValue, lowerValue);
but if upperValue
can be lesser than lowerValue
then use different names. 但是如果
upperValue
可以小于lowerValue
则使用不同的名称。
Your first argument must always be the lower one. 您的第一个参数必须始终是较低的参数。
From documentation of SQL: 从SQL文档中:
test_expression [ NOT ] BETWEEN begin_expression AND end_expression
BETWEEN returns TRUE if the value of test_expression is greater than or equal to the value of begin_expression and less than or equal to the value of end_expression . 如果test_expression的值大于或等于begin_expression的值且小于或等于end_expression的值, 则 BETWEEN返回TRUE 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.