Maybe this is what you want:

http://docs.djangoproject.com/en/1.2/topics/db/aggregation/#filtering-on-annotations

On Mon, Sep 13, 2010 at 3:32 PM, Phlip <[email protected]> wrote:

> Djangoids:
>
> Consider this QuerySet:
>
>   Blog.objects.filter(comment__date__range=(self.yesterday,
> self.tomorrow))
>
> It returns all the blogs with any comment (as a side note, it seems to
> return each blog redundantly, to allow the SELECT to differ each
> returned row by comment).
>
> I need every Blog whose first comment appears in the date range:
>
> SELECT * FROM blog
>  INNER JOIN comment ON comment.blog_id = blog.id
> WHERE MIN(comment.date) BETWEEN '2010-09-12' AND '2010-09-14'
> GROUP BY(blog.id)
>
> Can I get that without dropping to raw SQL?
>
> --
>  Phlip
>  http://zeekland.zeroplayer.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<django-users%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to