#10060: Multiple table annotation failure
----------------------------------------------+-----------------------------
          Reporter:  [email protected]  |         Owner:     
            Status:  new                      |     Milestone:  1.1
         Component:  ORM aggregation          |       Version:  SVN
        Resolution:                           |      Keywords:     
             Stage:  Accepted                 |     Has_patch:  0  
        Needs_docs:  0                        |   Needs_tests:  0  
Needs_better_patch:  0                        |  
----------------------------------------------+-----------------------------
Comment (by bendavis78):

 If anyone were to fix this,  the first question to ask would be how you
 would structure the SQL.  I'm not an SQL efficiency expert,  but I know
 one way to get the correct result would be to use subqueries in the SELECT
 clause:

 For example,  let's say I have a User,  !PointEarning w/
 !ForeignKey(User), and !PointExpense w/ F!oreignKey(User).    Let's say I
 want a query to get the user's email, total points earned, and total
 points spent.:

 {{{
 SELECT auth_user.id, auth_user.email, (SELECT SUM(points) FROM
 app_pointearning WHERE user_id=auth_user.id) AS points_earned,  (SELECT
 SUM(points) FROM app_pointexpense WHERE user_id=auth_user.id) AS
 points_spent FROM auth_user
 }}}

 Another way, I believe, is to join on derived tables (sub-queries).
 Whatever way we decide to write the SQL,  django could perhaps detect when
 we're using aggregates accross multiple joins, and alter the structure of
 the query accordingly.   Seems like it could be kinda messy, but at least
 the results would be more what the user expected.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10060#comment:7>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to