you never need any columns in the "columns" clause of a SELECT to control filtering/ordering of rows. place the criterion you'd like in the ORDER BY. query.order_by(func.sum(colname))
On Mar 21, 2009, at 9:01 AM, Victor Lin wrote: > > Hi, > > I got some query like this: > > sites = db.session.query(model.Site, func.sum > (model.ProxyOnAir.listeners).label('listeners')).\ > join(model.OnAir).\ > outerjoin(model.ProxyOnAir).\ > group_by(model.Site.user_id).\ > order_by('listeners') > > The only column I needed is Site, but however, I also need the sum of > listeners to sort sites. The result will be > [ > (Site, listeners), > (Site, listeners), > (Site, listeners), > ... > ] > > I know I can handle it like this: > map(lambda x: x[0], result) > But if I do that, I can't use result[:limit] which imply LIMIT syntax. > So my question is, how can I exclude some columns that I don't need? I > want the result be a list like this [Site, Site, Site, ...] > > Thanks. > Victor Lin. > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---