如何在 PhalconPHP 中为单个 table 列实现多个条件
How to implement multiple conditions for single table column in PhalconPHP
在 status
为 abanadoned
或 completed
的计划中查找节省的金额的正确语法是什么:
$total = self::sum([
'column' => 'amount_saved_so_far',
'conditions' => 'status = "completed" AND user_id = :user_id:',
//find plans with a status of abandoned as well
'bind' => ['user_id' => $userId]
]);
你可以简单地做,这是完美的解决方案:
$total = self::sum([
'column' => 'amount_saved_so_far',
'conditions' => '(status = "completed" OR status = "abanadoned")
AND user_id = :user_id:',
'bind' => ['user_id' => $userId]
]);
或者另一种选择是使用数组绑定:
$total = self::sum([
'column' => 'amount_saved_so_far',
'conditions' => 'status IN ({vars:array}) AND user_id = :user_id:',
'bind' => [
'vars' => ['completed', 'abanadoned'],
'user_id' => $userId
]
]);
如果 IN 子句有更多值,第二个选项更优雅、更实用。
在 status
为 abanadoned
或 completed
的计划中查找节省的金额的正确语法是什么:
$total = self::sum([
'column' => 'amount_saved_so_far',
'conditions' => 'status = "completed" AND user_id = :user_id:',
//find plans with a status of abandoned as well
'bind' => ['user_id' => $userId]
]);
你可以简单地做,这是完美的解决方案:
$total = self::sum([
'column' => 'amount_saved_so_far',
'conditions' => '(status = "completed" OR status = "abanadoned")
AND user_id = :user_id:',
'bind' => ['user_id' => $userId]
]);
或者另一种选择是使用数组绑定:
$total = self::sum([
'column' => 'amount_saved_so_far',
'conditions' => 'status IN ({vars:array}) AND user_id = :user_id:',
'bind' => [
'vars' => ['completed', 'abanadoned'],
'user_id' => $userId
]
]);
如果 IN 子句有更多值,第二个选项更优雅、更实用。