【问题标题】:Aggregate function in Kohana Jelly ORMKohana Jelly ORM 中的聚合函数
【发布时间】:2011-01-03 20:52:56
【问题描述】:

您能帮我了解如何使用 Kohana - Jelly 模块插入聚合函数吗?

I.E.我需要显示以下查询的结果:

SELECT COUNT('total_item') AS tot FROM items WHERE category_id = '1'

非常感谢您的帮助。

谢谢

【问题讨论】:

    标签: php kohana jelly


    【解决方案1】:

    通过简要查看文档。会是这样的

    $cnt = Jelly::select("tot")->select("count('total_item') AS total")
           ->where("category_id","=", 1)
           ->limit(1)
           ->execute();
    
    echo $cnt->total;
    

    希望有帮助!

    【讨论】:

      【解决方案2】:

      我在 kohana 3.1 中使用以下功能

      $count = ORM::factory('items')->select(array('COUNT("id")', 'total_items'))->find_all();

      【讨论】:

        【解决方案3】:

        也许这样会更好:

        $count = Jelly::select('item')->where('category', '=', 1)->count();
        

        这将生成这个查询:

        SELECT COUNT(*) AS `total` FROM `items` WHERE `category_id` = 1
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-07-31
          • 1970-01-01
          • 2022-12-29
          • 1970-01-01
          • 2014-06-07
          • 2021-12-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多