CakePHP:find('count') 和 DISTINCT 字段与 find('all') 和 GROUP BY 字段
我正在 CakePHP 中构建查询,但无法在 find('count')
中使用 GROUP BY
语句,因为它会引发错误。因此,我在字段列表中使用 DISTINCT
字段来代替 GROUP BY
语句。
因此,从 find('count', array('group' => 'field'))
我现在有了 find('count', array('fields' => ' DISTINCT field'))
在应用程序的另一部分,我使用 find('all')
来获取与上面相同的记录。在这里,我可以使用 GROUP BY
语句,因此我有:
find('all', array('group' => 'field'))
My问题是:上述两个查询是否返回相同的结果?简而言之,我想确保 DISTINCT field
与 find('count')
组合返回的结果与 GROUP BY field
与 组合返回的结果相同>查找('全部')
。
I am building a query in CakePHP, but cannot use a GROUP BY
statement in my find('count')
as it throws an error. Therefore I used instead of the GROUP BY
statement a DISTINCT
field in my fieldlist.
So, from find('count', array('group' => 'field'))
I now have find('count', array('fields' => 'DISTINCT field'))
In another part of the application, I am using a find('all')
to fetch the same records as above. Here, I am able to use the GROUP BY
statement, so I have:
find('all', array('group' => 'field'))
My question is: are both of the queries described above returning the same results? Briefly I want to be sure that DISTINCT field
combined with find('count')
returns the same results as GROUP BY field
combined with find('all')
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一篇旧帖子,但我需要这方面的帮助并最终找到了答案,所以就在这里。
如果你这样做,它们将是相同的......
An old post, but I needed help on this and eventually found the answer, so here it is.
They will be the same if you do this...