如何使用算术运算符在yii2选择查询使用模型名称



我的表:-账户

| id | total_due | balance_amount |
| -- | --------- | -------------  |
|  1 | 200       | 100            |
|  2 | 400       | 50             |

我想从帐目表中查一下已付款的数额。我的型号是Account。

查找padi金额的postgres查询是

$query = "SELECT total_due - balance_amount as paid from account order by total_due - balance_amount desc";

我上面查询的Yii代码是

Account::find()->select(['total_due - balance_amount as paid'])->orderBy(['total_due - balance_amount'] => SORT_DESC])->all(); 

显示错误

列"total_due-balance_amount";不存在

Account::find()->select(['total_due - balance_amount as paid'])->orderBy(['paid' => SORT_DESC])->all()

相关内容

  • 没有找到相关文章

最新更新