[英]Count number of results in a View
I need to count how many people belong in pre-defined groups (this is easy to do in SQL using the SELECT COUNT statement). 我需要计算有多少人属于预定义的组(使用SELECT COUNT语句在SQL中很容易做到)。 My Views query runs fine and displays the actual data in my table, but I simply need to know how many results it found.
我的视图查询运行正常,并在我的表中显示实际数据,但我只需要知道它找到了多少结果。
However there doesn't seem to be a COUNT option in views. 但是,视图中似乎没有COUNT选项。 I am guessing I am going to have to use some sort of views hook, and then stick the result in the table.
我猜我将不得不使用某种视图钩子,然后将结果粘贴在表格中。
Here's a quick example of what i'm trying to achieve: 这是我想要实现的一个简单示例:
My Table
----------------------
Group A | 20 people
Group B | 63 people
and so on. 等等。
(I've tried using the Views_Calc module, but I get errors because it is not quite stable yet.) (我尝试过使用Views_Calc模块,但是我收到了错误,因为它还不太稳定。)
Anybody know of an easy way to count results in Views? 有人知道在Views中计算结果的简单方法吗?
Here's a good do thread about it: http://drupal.org/node/131031 这是关于它的好主题: http : //drupal.org/node/131031
Although if you JUST need the count and not the other things Views offers (field formatting & ordering, etc), why not just code up the proper SELECT COUNT statement and call it a day? 虽然如果你只需要计数而不是View提供的其他东西(字段格式和排序等),为什么不只是编写正确的SELECT COUNT语句并将其称为一天?
(If you DO in fact need those other pieces Views offers, there are many examples on that thread above.) (如果你确实需要View提供的其他部分,那么上面的那个帖子就有很多例子。)
I'm currently using the Views Group By module for this type of functionality. 我目前正在使用Views Group By模块来实现此类功能。
I'm actually working on adding other aggregate functions ( MIN
, MAX
, etc.) into it but since you only need the COUNT
function, I think it's a pretty good option. 我实际上正在努力添加其他聚合函数(
MIN
, MAX
等),但由于你只需要COUNT
函数,我认为这是一个非常好的选择。
All you have to do (after installing and enabling the module), in the View that you are interested: 您需要做的所有事情(在安装和启用模块之后),在您感兴趣的视图中:
GROUP BY
. GROUP BY
的条件的字段。 Fields to Group On
. Fields to Group On
。 SQL Aggregation Function
should be set to Count
. SQL Aggregation Function
应设置为Count
。 Aggregate with the SQL function
set to a field that you are not grouping by. Aggregate with the SQL function
设置为您未分组的字段的Aggregate with the SQL function
字段。 (This will be added into the COUNT
function like COUNT(<this field>)
in SQL) COUNT
函数中,如SQL中的COUNT(<this field>)
) Update
. Update
。 You should have the COUNT
output from the field that you selected to aggregate. 您应该从您选择要聚合的字段中输出
COUNT
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.