显示SELECT COUNT的值

时间:2018-10-10 15:47:21

标签: php

我正在使用RedBeanPHP,我想知道一列的最重复值。

我有这个:

$books = R::getAll('
    SELECT `autor`,
        COUNT(`autor`) AS `value_occurrence` 
    FROM `fichas`
    GROUP BY `autor`
    ORDER BY `value_occurrence` DESC
    LIMIT 10
');

foreach( $books as $book ) {
    echo $book['autor'] . '<br />';
}

我还想显示“ autor”值重复的次数。例如:

John Smith (10)
Jack Sparrow (7)

如何获取这样的值?

1 个答案:

答案 0 :(得分:1)

获取author信息的方式相同:

echo $book['value_occurrence'];

在这种情况下,您可以使用

echo $book['autor'] . '(' . $book['value_occurrence'] . ')';