On Tuesday, December 8, 2015 at 5:28:08 PM UTC+2, Michael wrote:
>
> On Tuesday, December 8, 2015 at 1:26:52 AM UTC-6, Anssi Kääriäinen wrote:
>>
>>
>> Come to think of it, we already have a workaround:
>> Book.objects.annotate(author_cnt=RawSQL("(select count(*) from author
>> where author.book_id = book.book_id)").
>>
>
> Yes, you can do a subquery to get the Sum or Count but then you cannot
> "filter": `qs.filter(author_cnt__gt=0)` won't work.
>
> I think it would require the correct "GROUP BY" and "HAVING" clause to be
> able to filter, correct?
>
This one actually does work with filter(). As the count is inside a
subselect, it can be used directly in the WHERE clause without GROUP BY or
HAVING. Using a direct count without a subselect wouldn't work.
- Anssi
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/f7516a98-5be5-49ba-8e40-1a49e95b9537%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.