【发布时间】:2016-08-03 12:01:35
【问题描述】:
我只是想对 column 求和。 我用了这段代码
$money = Income::sum('money');
这个也累了
$money = Income::select(DB::raw('sum(money)'))->get();
但它抛出错误。我使用 postgresql 作为我的数据库。 错误信息:
SQLSTATE[42883]: Undefined function: 7 ERROR: function sum(character varying) does not exist
LINE 1: select sum("money") as aggregate from "incomes"
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. (SQL: select sum("money") as aggregate from "incomes")
我的桌子:
incomes
+----+---------+-------+
| id | orderid | money |
+----+---------+-------+
| 1 | 2343 | 23 |
| 2 | 2344 | 55 |
+----+---------+-------+
【问题讨论】:
-
你能发布数据库架构吗?
-
@Jaimin 已编辑帖子
-
这不是架构;你能发布建立收入表的数据库迁移文件吗?或者使用psql,可以运行
\d {income table name}并分享结果吗? -
已解决@ChrisForrence。这是我的错。我用列字符串代替整数
标签: php postgresql laravel eloquent