postgresql - 如何在yii2中使用算术运算符选择使用模型名称的查询?
问题描述
我的桌子:- 帐户
| id | total_due | balance_amount |
| -- | --------- | ------------- |
| 1 | 200 | 100 |
| 2 | 400 | 50 |
我想从帐户表中找到支付的金额。我的模型是帐户。
用于查找 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()
推荐阅读
- python - 在 Python 中修改日志记录级别
- google-fusion-tables - 在欧几里得空间而不是地图上可视化数据
- r - 为什么 R 中的正则表达式搜索查询由字符串表示?
- json - 在定义对象中定义的子模式可以引用另一个子模式吗?
- mysql - 如何为 BLOB 数据类型设置默认值
- javascript - 如何在一个循环中执行所有函数,其中需要调用一些函数作为异步函数的回调
- docker - 如何将多个(子)域绑定到 docker 中的一个容器,在 traefik 中具有不同的端口
- jquery - jquery数据表排序按钮在标题列中不可用
- javascript - 在我的函数中构建我的条件不起作用。程序不想执行我的条件?
- android - Android 服务未从 Activity 启动