【问题标题】:cakephp: group by is missing from generated querycakephp:生成的查询中缺少分组依据
【发布时间】:2023-03-24 07:32:01
【问题描述】:

我有一个简单的模型,我想在其中找到每个日期的一些计数数据。 为了做到这一点,我做了这个发现:

$statsubscriptions = $this->Nlist->Statsubscription->find('all',
    array(
     'fields'=>array('Statsubscription.date','Statsubscription.type','COUNT(*) as qs'),
     'qroup'=>array('Statsubscription.date','Statsubscription.type'),
     'conditions'=>array('Statsubscription.nlist_id'=>$id),
     'recursive'=>-1,
      )
 );

但它不起作用。生成的查询如下:

SELECT `Statsubscription`.`date`, `Statsubscription`.`type`, COUNT(*) as qs
FROM `statsubscriptions` AS `Statsubscription`
WHERE `Statsubscription`.`nlist_id` = 1 

GROUP BY 完全缺失...而不是上面的,我希望生成这个查询:

    SELECT `Statsubscription`.`date`, `Statsubscription`.`type`, COUNT(`Statsubscription`.`id`) as qs
    FROM `statsubscriptions` AS `Statsubscription`
    WHERE `Statsubscription`.`nlist_id` = 1
    GROUP BY `Statsubscription`.`date`, `Statsubscription`.`type`

我怎样才能做到这一点?缺少 GROUP BY 的原因可能是什么?

【问题讨论】:

    标签: cakephp cakephp-1.3


    【解决方案1】:

    你写的是qroup而不是group(那是q而不是g)。这就是为什么它不起作用。

    P.S.: get some sleep...

    【讨论】:

    • 天啊,非常感谢。你说得对,我要睡觉了 :) 我浪费了 1.5 个小时,并没有注意到错字...
    猜你喜欢
    • 2021-07-04
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    相关资源
    最近更新 更多