List Info

Thread: Can the DB API do this?




Can the DB API do this?
user name
2006-12-30 19:05:53
Hi all --

I'm trying to figure out whether a query like the following
can be done
through the DB API (for maintainability), or whether I'll
have to
execute it as custom SQL:

SELECT SUM(tourney_score.amount) AS team_total,
tourney_team.id
FROM tourney_score, tourney_team, tourney_player
WHERE tourney_score.player_id = tourney_player.id
AND tourney_player.team_id = tourney_team.id
GROUP BY tourney_team.id

This basically computes the total score for each team of
players in a
tournament.  Is this too complex for the API?  I couldn't
quite figure
out how to execute it.

Thanks!


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

Can the DB API do this?
user name
2006-12-30 19:17:17
Hi there,

Check out:
http://ww
w.djangoproject.com/documentation/db_api/#extra-select-none-
where-none-params-none-tables-none

In a nutshell:
Team.objects.extra(
    select={
        'team_total': 'SUM(tourney_score.amount)'
    },
)

You may want to add it as a manager to the model:
http://www.djangoproject.com/documentation/model_a
pi/#managers


On Dec 31, 8:05 am, "ringemup" <ringe...gmail.com> wrote:
> Hi all --
>
> I'm trying to figure out whether a query like the
following can be done
> through the DB API (for maintainability), or whether
I'll have to
> execute it as custom SQL:
>
> SELECT SUM(tourney_score.amount) AS team_total,
tourney_team.id
> FROM tourney_score, tourney_team, tourney_player
> WHERE tourney_score.player_id = tourney_player.id
> AND tourney_player.team_id = tourney_team.id
> GROUP BY tourney_team.id
>
> This basically computes the total score for each team
of players in a
> tournament.  Is this too complex for the API?  I
couldn't quite figure
> out how to execute it.
> 
> Thanks!


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

Can the DB API do this?
user name
2006-12-30 21:01:54
Thanks...   I don't see any info, though, on how to tell it
what to
group by.  Is that possible, or is it smart enough to figure
it out on
its own?


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

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )