gpt4 book ai didi

php - 如何在 PhalconPHP 中为单个表列实现多个条件

转载 作者:行者123 更新时间:2023-11-29 01:51:55 25 4
gpt4 key购买 nike

statusabanadonedcompleted 的计划中查找节省的金额的正确语法是什么:

$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]
]);

或者另一种选择是使用数组绑定(bind):

$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 子句有更多值,第二个选项更优雅、更实用。

关于php - 如何在 PhalconPHP 中为单个表列实现多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39344232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com