【发布时间】:2014-04-26 23:40:27
【问题描述】:
我有下一条声明:
$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
)
有什么想法吗?
谢谢
【问题讨论】:
标签: sql count null group-by cakephp-2.0