Aggregate function in Kohana Jelly ORM
Pergunta
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
Solução
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
Outras dicas
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();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow