Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在select语句中使用“between”_Php_Mysql - Fatal编程技术网

Php 如何在select语句中使用“between”

Php 如何在select语句中使用“between”,php,mysql,Php,Mysql,这本应是一个简单的解决方案,但我无法预测我的未来。 我有一张桌子 这是我的疑问 $salary=2000; select deductions from nhif_tbl where to_end <=$salary and start_from >= $salary; 查询返回null。 我的问题是如何修改查询,以便在这种情况下获得正确的扣减额“60”您的“终点”应该比“起点”多999 像这样 select deductions from nhif_tbl where t

这本应是一个简单的解决方案,但我无法预测我的未来。 我有一张桌子

这是我的疑问

 $salary=2000;  

select deductions from nhif_tbl where to_end <=$salary and start_from >= $salary;
查询返回null。 我的问题是如何修改查询,以便在这种情况下获得正确的扣减额“60”

您的“终点”应该比“起点”多999

像这样

select deductions from nhif_tbl where to_end >=$salary and start_from <= $salary;

那很明显,试着扭转这种状况

....where to_end >=$salary and start_from <= $salary;
让我们做一些条件分析
当条件开始时,不应该从nhif中选择扣除额,从哪里结束>=$salary和start两个条件之间的距离只有499。如果salary是1000呢?是的,逻辑不应该是这样的。这个解决方案首先出现在我的脑海中,然后发布!改变。。。
select deductions from nhif_tbl where to_end >=$salary and start_from <= $salary;
....where to_end >=$salary and start_from <= $salary;