On Thu, Jul 23, 2009 at 3:24 PM, Michael Bayer<mike...@zzzcomputing.com> wrote:

> im assuming you're using MySQL since the GROUP BY below doesn't
> accommodate every column in the subquery (would be rejected by most DBs).

Corrected.  It was Sqlite, but good catch.

> youll want to query each column individually that is part of what you are
> grouping by.    i think you also need to use func.max() here and not
> func.min().

Yes, dumbpants on me there!

 the join of the subquery to parent table is then probably
> just on hop_id.   no "correlation" of subquery is needed either since you
> are intersecting two complete sets together (all routes intersected with
> all "max hop id" routes grouped by x, y, z).
>

How do I implement this join?  If I do this:

sq = 
session.query(Route.ts,Route.startpoint,Route.target,func.max(Route.hop_id).label('max_hop'))
sq = sq.group_by(Route.ts,Route.startpoint,Route.target).subquery()

then:

q = session.Query(Route,*sq.c).join(???)

What would that join be on?  Hop_id isn't in the subquery.

I don't mean to be dense, but I'm not quite getting your response.
Perhaps I don't understand what correlated subqueries in  SqlA are.
Is there is a reference that explains where they're used?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to