如何在cakephp查询中使用group_contact?

如何在cakephp查询中使用group_contact?,cakephp,cakephp-2.0,cakephp-2.3,cakephp-2.1,Cakephp,Cakephp 2.0,Cakephp 2.3,Cakephp 2.1,如何用cakephp编写此查询 请帮助我用cakephp编写上述查询。我不知道如何在cakephp查询中编写group\u contact。我正在使用cakephp 2x试试这个 SELECT GROUP_CONCAT(usertype_name SEPARATOR ','), customer_name FROM `pre`.`customer` AS `Viewcustomer` WHERE `Viewcustomer`.`customer_status` = 0 AND `Viewcust

如何用cakephp编写此查询

请帮助我用cakephp编写上述查询。我不知道如何在cakephp查询中编写
group\u contact
。我正在使用cakephp 2x

试试这个

SELECT GROUP_CONCAT(usertype_name SEPARATOR ','), customer_name FROM `pre`.`customer` AS `Viewcustomer` WHERE `Viewcustomer`.`customer_status` = 0 AND `Viewcustomer`.`customer_type` = 'A1'  
GROUP BY `customer_id`  DESC
请检查cakephp文档以供参考

SELECT GROUP_CONCAT(usertype_name SEPARATOR ','), customer_name FROM `pre`.`customer` AS `Viewcustomer` WHERE `Viewcustomer`.`customer_status` = 0 AND `Viewcustomer`.`customer_type` = 'A1'  
GROUP BY `customer_id`  DESC

参考请查看cakephp 3.X中的cakephp文档

$this->ModelName->query('SELECT GROUP_CONCAT(usertype_name SEPARATOR ','), customer_name FROM `pre`.`customer` AS `Viewcustomer` WHERE `Viewcustomer`.`customer_status` = 0 AND `Viewcustomer`.`customer_type` = 'A1'
GROUP BY `customer_id`  DESC');

在CakePHP 3.X中

$this->ModelName->query('SELECT GROUP_CONCAT(usertype_name SEPARATOR ','), customer_name FROM `pre`.`customer` AS `Viewcustomer` WHERE `Viewcustomer`.`customer_status` = 0 AND `Viewcustomer`.`customer_type` = 'A1'
GROUP BY `customer_id`  DESC');

试试谷歌或CakePHP官方网站。试试谷歌或CakePHP官方网站。我知道这个方法。。有没有其他选项,比如$this->Model->find()没有。您也可以试试这个$db=$this->getDataSource()$db->fetchAll('SELECT GROUP_CONCAT(usertype_name SEPARATOR')),客户名称从
pre
customer
作为
Viewcustomer
其中
Viewcustomer
customer\u status
=0和
Viewcustomer
customer\u type
=“A1”分组依据
customer\u id
DESC);在查询中,我将组_CONCAT(usertype_name SEPARATOR',')重命名为“usertypename”。但从某种程度上看,这是一个错误。。Undefined index.plz打印并检查阵列。我猜“usertypename”的索引将为零,而不是在数组中。我知道这个方法。。有没有其他选项,比如$this->Model->find()没有。您也可以试试这个$db=$this->getDataSource()$db->fetchAll('SELECT GROUP_CONCAT(usertype_name SEPARATOR')),客户名称从
pre
customer
作为
Viewcustomer
其中
Viewcustomer
customer\u status
=0和
Viewcustomer
customer\u type
=“A1”分组依据
customer\u id
DESC);在查询中,我将组_CONCAT(usertype_name SEPARATOR',')重命名为“usertypename”。但从某种程度上看,这是一个错误。。Undefined index.plz打印并检查阵列。我猜“usertypename”的索引将为零,而不是在数组中。