0

在以下 cakephp mysql 查询中,我如何找到每次分组的行数?

$groupBy = 'PropertyViewer.ip_address';
$this->paginate = array(
  "group" => array( $groupBy ),
  "order" => array( "PropertyViewer.id desc" ) );
$view_info = $this->paginate( 'PropertyViewer', $conditions );
$this->set( 'view_info', $view_info );`
4

1 回答 1

1

您可以按照以下方式进行操作,但是我没有尝试过,但它会起作用。

$groupBy = 'PropertyViewer.ip_address'; 
$this->paginate = array( "fields" => (..., 'COUNT(PropertyViewer.id) AS total_rows),
                         "group" => array( $groupBy ),
                         "order" => array( "PropertyViewer.id desc" ) );
$view_info = $this->paginate( 'PropertyViewer', $conditions );
$this->set( 'view_info', $view_info );`

或者,如果您需要经常使用它,您也可以在模型中创建一个虚拟字段。

于 2012-07-06T07:13:44.790 回答