我需要相当于
SELECT SUM(balance) as "total_balance" FROM users;
在科哈纳 3。
那么,如何在 Kohana3 中找到表格balance列的总和?users
$total_balance = ORM::factory ( 'user' )->find ();//I want to change this string to find total_balance to be a sum of the balance column.
我需要相当于
SELECT SUM(balance) as "total_balance" FROM users;
在科哈纳 3。
那么,如何在 Kohana3 中找到表格balance列的总和?users
$total_balance = ORM::factory ( 'user' )->find ();//I want to change this string to find total_balance to be a sum of the balance column.
ORM中没有SUM()等价物。Kohana ORM 没有提供与本机 SQL 函数相当的功能。
作为一种解决方法,使用DB::select()如下DB::expr():
$total_balance = DB::select(array(DB::expr('SUM(`balance`)'), 'total_balance'))
->from('users')
->execute()
->get('total_balance');
产生的查询:
SELECT SUM(`balance`) AS `total_balance` FROM `users`