Aggregate function in Kohana Jelly ORM
Question
could you help me to find out how to insert aggregate function using Kohana - Jelly module?
I.E. i need to show result of following query :
SELECT COUNT('total_item') AS tot FROM items WHERE category_id = '1'
really appreciate your help.
thanks
Solution
Perhaps something like this would be better:
$count = Jelly::select('item')->where('category', '=', 1)->count();
This would generate this query:
SELECT COUNT(*) AS `total` FROM `items` WHERE `category_id` = 1
OTHER TIPS
from briefly looking at the documentation. It's going to be something like
$cnt = Jelly::select("tot")->select("count('total_item') AS total")
->where("category_id","=", 1)
->limit(1)
->execute();
echo $cnt->total;
hope that helps!
i m using following with kohana 3.1
$count = ORM::factory('items')->select(array('COUNT("id")', 'total_items'))->find_all();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow