查询mysql没有返回预期的

时间:2017-01-16 12:41:42

标签: php mysql pdo

IMAGE

这是我的数据库数据。我想用

查询记录
  

$ period = 3

     

$ dependent + 1 = 1

     

$ birstat = 2

     

$ netpay = 10741.2

我的查询是:

$stmt = $dbh->prepare("SELECT * FROM af_hris_masterfile_tax_table WHERE "
. " payroll_period = :period AND "
. "status = :birstat AND "
. "dependent = :dependent AND "
. "(cast(min_compensation as decimal(10, 6)) <= :name AND :name <= cast(max_compensation as decimal(10, 6)) OR cast(min_compensation as decimal(10, 6)) <= :name AND LOWER(max_compensation) = 'above') ");
//        . "(min_compensation <= :name AND :name <= max_compensation) OR (min_compensation <= :name AND LOWER(max_compensation) = 'above') ");
$stmt->bindValue(":name", ($netpay), PDO::PARAM_STR);
$stmt->bindValue(":dependent", ($dependent + 1), PDO::PARAM_STR);
$stmt->bindValue(":period", $period, PDO::PARAM_STR);
$stmt->bindValue(":birstat", $birstat, PDO::PARAM_STR);

使用此查询并使用set参数,我希望获得sys_id 111的记录,因为10741.2大于7917.01但小于12500

但我得到的记录是sys_id 112的记录

我知道我的错误。

赞赏任何想法

更新

根据建议

. "(cast(min_compensation as decimal(10, 6)) <= :name AND :name1 <= cast(max_compensation as decimal(10, 6)) OR cast(min_compensation as decimal(10, 6)) <= :name2 AND LOWER(max_compensation) = 'above') ");
//        . "(min_compensation <= :name AND :name <= max_compensation) OR (min_compensation <= :name AND LOWER(max_compensation) = 'above') ");
        $stmt->bindValue(":name", floatval($netpay), PDO::PARAM_STR);
        $stmt->bindValue(":name1", floatval($netpay), PDO::PARAM_STR);
        $stmt->bindValue(":name2", floatval($netpay), PDO::PARAM_STR);

更新 当我使用

. "(  min_compensation <= :name AND :name <= max_compensation ) ");
 $stmt->bindValue(":name", ($netpay));

我收到了sys_id [{"sysid":"106","min":"1.01","max":"2083","payrollperiod":"3","status":"2","dependent":"1",....

0 个答案:

没有答案