Cakephp,group by - count函数返回null

时间:2014-03-20 08:48:27

标签: sql count null group-by cakephp-2.0

我有下一个声明:

$lead_count = $this->Lead->find("list", array("conditions" => array("chosen_country_id" => $countries, "lead_type" => "Consumer"), 
                                                    "fields" => array('Lead.status', 'count(Lead.id)'),
                                                    "group" => "Lead.status"));

此声明中形成的查询是:

SELECT "Lead"."status" AS "Lead__status", count("Lead"."id") 
FROM "public"."leads" AS "Lead" 
WHERE chosen_country_id IN (167, 201, 203, 39) AND "lead_type" = 'Consumer' 
GROUP BY "Lead"."status"

如果我在数据库上手动运行此查询,结果为:

    Lead__status         | count
-----------------------------+-------
 Contacted                   |     1
 Assigned to lead dispatcher |     1
 On call                     |     3
 Sent to Distributor         |     1
 Call attempted 1            |     1
 New                         |   241
 Mark as invalid             |     1

但在我的网页上,结果是:

阵列(

'Contacted' => null,
'Assigned to lead dispatcher' => null,
'On call' => null,
'Sent to Distributor' => null,
'Call failed 1' => null,
'New' => null,
'Mark as invalid' => null

任何想法为什么?

由于

1 个答案:

答案 0 :(得分:0)

请从这个帖子中找到你的回答我认为这是一个微笑的问题..

CakePHP GROUP and COUNT items returned in list