GROUB BY问题 - (使用ORM Doctrine-DQL) [英] GROUB BY problems-(Using ORM Doctrine-DQL)

查看:262
本文介绍了GROUB BY问题 - (使用ORM Doctrine-DQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

英语不是我的母语,所以请原谅我的编辑。

我正在使用php框架:Symfony 2,带有Doctrine。


我正在进行下一个查询:

- >

Hi, English is not my native language, so please excuse my redaction.
I′m using the php framework: Symfony 2, with Doctrine.

I′m doing the next query:
->

展开 | 选择 | Wrap | 行号

推荐答案

SELECT子句中的所有内容必须位于GROUP BY或AGGREGATE函数中。您所在的字段e不在GROUP BY或AGGREGATE函数中。
Everything that''s in your SELECT clause must either be in a GROUP BY or an AGGREGATE function. Your field that you call "e" is not in a GROUP BY or AGGREGATE function.


我在SQL中知道这是做到这一点的方法,但这里是Doctrine官方文档中的一个例子:

SELECT u,count(g.id)FROM Entities \User u JOIN u.groups g GROUP BY u.id

你可以看到你是一个对象实体用户和u不完全在group by子句中。我做了同样的事情我想通过字段estudiante和clase选择实体Evaluacion分组。我还使用聚合函数AVG来查找名为evaluationacion的整数字段的平均值。
Well I know in SQL that''s the way to do it, but here''s an example from the Doctrine official documentation:
SELECT u, count(g.id) FROM Entities\User u JOIN u.groups g GROUP BY u.id
as you can see u is an object of the entity user and u is not entirely in the group by clause. I did the same I want to select the entity Evaluacion grouping by the fields estudiante and clase. I also use an aggregate function AVG to find the average of an integer field named evaluacion.


可能是程序允许您不将除id之外的所有字段放入组中的情况。 ,但这意味着如果你想从e中选择任何东西或所有东西,你仍然需要将e的id放在组中。


如果你看一下你刚发布的例子对于你原来帖子中的SQL,你会发现你的SQL与你发布的工作样本相比仍然是错误的。


基本上,你得到的错误就是错误当你在SELECT子句中有一些不在GROUP BY中的东西时会发生这种情况。无论您使用哪个数据库,这都是错误的意思。即使该特定实现允许您不将大多数字段放在组中,也不意味着您可以忽略每个字段,这就是错误信息告诉你的。
It may be the case that the program allows you to not put everything except the id in the group by, but that means if you want to select anything or everything from e, you still need to put the id of e in the group by.

If you look at the example you just posted to your SQL in your original post, you will see that your SQL is still wrong compared to the working sample that you posted.

Basically, the error you''re getting is the error that occurs when you have something in the SELECT clause that''s not in the GROUP BY. It''s what that error means regardless of which database you''re working in. Even if that particular implementation allows you to not put most of the fields in the group by, that doesn''t mean you can leave out every field, and that is what the error message is telling you.


这篇关于GROUB BY问题 - (使用ORM Doctrine-DQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆