关于 django 中 Group_by 的问题
更新 这已被确认为 1.3 版本的错误。这是票证 http://code.djangoproject.com/ticket/15709
所以我想实现这个 SQL:
selelct id, count(*), max(insert_date) as m_d
from Book
group by id
这是 Django ORM 查询:
q = Book.objects.values('id').annotate(c = Count('id'), m_d = Max('insert_date')).order_by()
但是,翻译后的 SQL 是这样的:
selelct id, count(*), max(insert_date) as m_d
from Book
group by id, id <-here is another id! It messed up things!
有人能解释一下吗?我正在使用 Django 1.3。谢谢!
UPDATE This has been confirmed to be a bug of the release 1.3. Here is the ticket http://code.djangoproject.com/ticket/15709
So I want to implement this SQL:
selelct id, count(*), max(insert_date) as m_d
from Book
group by id
Here is the Django ORM query:
q = Book.objects.values('id').annotate(c = Count('id'), m_d = Max('insert_date')).order_by()
However, the translated sql is like this:
selelct id, count(*), max(insert_date) as m_d
from Book
group by id, id <-here is another id! It messed up things!
Can any one shed some light on this? I am using Django 1.3. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这已被确认为 1.3 版本的错误。这是票证 http://code.djangoproject.com/ticket/15709
This has been confirmed to be a bug of the release 1.3. Here is the ticket http://code.djangoproject.com/ticket/15709