If you don't use a subquery, you can use the `desc("column")` in 
`sqlalchemy`.  (there is an `asc()` as well).  Below I use `label('name')` 
to specify the result column name for computed field, then order by it.

    results = dbSession.query(
           model.Foo.a,
           sqlalchemy.func.count(Model.Foo.b).label('count_b')
     )\
     .group_by(model.Foo.a)\
     .order_by(sqlalchemy,desc('count_b')\
     .all()

If you are using a subquery for additional processing or joins, you can use 
`label()` to specify the name for the computed column, then access that 
column as an attribute on the `.c` columns attribute of the subquery 
object.  

    inner_query = dbSession.query(
           model.Foo.a,
           sqlalchemy.func.count(Model.Foo.b).label('count_b')
     )
     inner_query = inner_query.subquery('query_foo')
     results = 
dbSession.query(inner_query.c.count_b.label('count_results')).all()

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to