加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 使用Propel统计和分组

发布时间:2020-12-13 14:13:28 所属栏目:PHP教程 来源:网络整理
导读:在Doctrine中,我可以做到: public function getCount() { $q = $this-createQuery('q') -select('*') -addSelect('count(q.name) as count') -groupBy('q.name') -orderBy('count DESC'); return $q-execute(); } 如何在Symfony 1.4中的Propel中做同样的事
在Doctrine中,我可以做到:
public function getCount() 
{        
        $q = $this->createQuery('q')
            ->select('*')
            ->addSelect('count(q.name) as count')
            ->groupBy('q.name')
            ->orderBy('count DESC');

        return $q->execute();        
}

如何在Symfony 1.4中的Propel中做同样的事情?

该死的!它比那更容易!

如果需要计算给定查询的结果行,则需要使用count()终止方法,基本上:

MyTableQuery::create()->count();

有关更多信息,请阅读以下文档部分:http://www.propelorm.org/documentation/03-basic-crud.html#query_termination_methods

如果要在查询中添加count或nb extra列,表示COUNT或SUM等SQL聚合函数,则应使用withColumn()方法:

$query = MyTableQuery::create()
    ->withColumn('COUNT(*)','Count')
    ->select(array('Name','Count'))
    ->groupByName()
    ->orderByCount()
    ;

$results = $query->find();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读