Symfony 1.4 Criteria addGroupByColumn 然后按最多排序

Symfony 1.4 Criteria addGroupByColumn then order by most

我使用 symfony 1.4,我想对一些数据进行分组,按分组列排序,然后 select 记录最多的那个。 我的代码如下所示:

$c = new Criteria();
$c->addGroupByColumn(MetricPeer::POST_TYPE_ID);
$c->addDescendingOrderByColumn(MetricPeer::POST_TYPE_ID);    
$posts = MetricPeer::doSelectOne($c);

我知道行“$c->addDescendingOrderByColumn(MetricPeer::POST_TYPE_ID);”它只是按数字对数据进行排序,这是不正确的。

public static function topPosts($limit,$source_id,$interval1,$interval2,$con = null) {
    if($con === null) $con = Propel::getConnection(self::DATABASE_NAME);
    $sql = "SELECT *, COUNT(post_id) AS value_occurrence FROM metric WHERE source_id LIKE ".$source_id." AND visit_out BETWEEN '".$interval1."' AND  '".$interval2."' GROUP BY post_id ORDER BY value_occurrence DESC LIMIT ".$limit."";
    $stmt = $con->prepare($sql);
    $stmt->execute();       
    $topreads = MetricPeer::populateObjects($stmt);
    return $topreads;
}

这是我目前的简陋解决方案,我认为它也可能对其他人有用。 谢谢。