Oh, i've manage to run:

SELECT id from table GROUP BY tablefield HAVING (COUNT(tablefield) >
1)

using ORM, but that's not what i want. The results vary.

If you're interested:

z = Comment.objects.all()
z.query.group_by = ['message']
z = z.annotate(num_messages=Count('message')).filter(num_messages__gt
= 1)

But results vary with the query in my first statement. Or, maybe i'm
not doing it right.

On 19 янв, 14:58, "[CPR]-AL.exe" <[email protected]> wrote:
> Oh, no, that wouldn't work with CharField. Or, maybe I'm doing
> something wrong.
>
> About a queryset - I mistaken aggregate() for annotate().
>
> On 19 янв, 14:52, "[CPR]-AL.exe" <[email protected]> wrote:
>
>
>
>
>
>
>
> > Wait, whhhhat... o.O I'l try that now, thx.
>
> > On Wed, Jan 19, 2011 at 2:50 PM, Tom Evans <[email protected]> wrote:
> > > On Wed, Jan 19, 2011 at 11:26 AM, [CPR]-AL.exe <[email protected]>
> > > wrote:
> > > > Hmm, yeah, but that still iterates over the objects and filters out
> > > > them by count on the application server, not on the database one :(
>
> > > > I'm bypassing it already in my running project, but I try to avoid
> > > > using raw sql as longer as it is possible. So, the question, actually
> > > > remains open.
>
> > > > It should go something like [pseudo-code]:
>
> > > Book.objects.values('tablefield').annotate(Count('tablefield')).filter('tab
> > >  lefield__count__gte
> > > > = 1)
>
> > > > But, of course, that wouldn't work, because annotate's return value is
> > > > not a queryset :(
>
> > > Er, says who?
>
> > > Organization.objects.annotate(num_grps=Count('usergroup')).filter(num_grps_
> > >  _gt=2).values_list('id',
> > > flat=True)
> > > [6L, 36L, 19L, 20L, 24L, 32L, 33L, 35L]
>
> > > Cheers
>
> > > Tom
>
> > > --
> > > 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%2Bunsubscribe@google
> > >  groups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
>
> > --
> > Sincerely yours, Alexey.

-- 
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