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!