过滤数组sql中的负数

时间:2012-11-23 03:08:23

标签: sql arrays filter

function get_patient_balance($pid) {
  if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) {
    $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
      "pid = ? AND billed = 1 AND activity = 1", array($pid) );
    $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
      "pid = ?", array($pid) );
    $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
      "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
      "pid = ?", array($pid) );
     return sprintf('%01.2f', $brow['amount'] + $srow['amount']
      - $drow['payments'] - $drow['adjustments']);
  }

以上是我正在使用的功能。在此函数中,$ brow从记帐表创建一个数组。在这个数组中有负数。我希望能够从SUM(费用)AS金额中排除这些数字,这样我才能将正数总和加起来。

1 个答案:

答案 0 :(得分:1)

  

我希望能够从SUM(费用)AS金额中排除这些数字,这样我才能将正数总数加起来。

所以,你只想添加所有费用> 0,对吧?如果我找到你的话,我认为这会有所帮助:

$brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
"pid = ? AND billed = 1 AND activity = 1 and fee > 0", array($pid) );