Sorry I didn't explain my self properly.

I want this query:
SELECT (date_format(date, '%%U')) AS `d`, SUM
(`profile_scorehistory`.`points`) AS `l` FROM `profile_scorehistory`
GROUP BY date_format(date, '%%U') HAVING  `d`= 2

How can I make it with ORM?

The other one was the only similar query I managed to make using the
ORM.


On Aug 12, 3:44 am, Russell Keith-Magee <freakboy3...@gmail.com>
wrote:
> On Wed, Aug 12, 2009 at 5:50 AM, lfrodrigues<lfrodrig...@gmail.com> wrote:
>
> > Hi,
>
> > I'm having some problems with "having":
>
> > I want to group by date and restrict to a given week, in my tests I
> > can do this:
> > select_data = {"d": """date_format(date, '%%U')"""}
> > ScoreHistory.objects.extra(select=select_data).values('d').annotate
> > (l=Sum("points")).filter(l=2).query.as_sql()
>
> > sql:
> > SELECT (date_format(date, '%%U')) AS `d`, SUM
> > (`profile_scorehistory`.`points`) AS `l` FROM `profile_scorehistory`
> > GROUP BY date_format(date, '%%U') HAVING SUM
> > (`profile_scorehistory`.`points`) = 2
>
> > Good but what I want to get is this:
> > sql:
> > SELECT (date_format(date, '%%U')) AS `d`, SUM
> > (`profile_scorehistory`.`points`) AS `l` FROM `profile_scorehistory`
> > GROUP BY date_format(date, '%%U') HAVING  `d`= 2
>
> I might be missing something here, but as far as I can make out,
> you're getting exactly what you've asked for. Your query contains
> filter(l=2) - that is, you're filtering on l, the SUM.
>
> > How can I force using having when I can't define the param in
> > annotate?
>
> I'm afraid I don't see how this relates to your original question.
>
> Yours,
> Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to