I got it:
from sqlalchemy.sql import func
stmt = session.query(Prod.store_id,
func.count('*').label('prod_count')).group_by(Prod.store_id).subquery()
obj_q = session.query(Store, stmt.c.prod_count).outerjoin(
(stmt,
Store.id==stmt.c.store_id)).order_by(stmt.c.prod_count.desc())
hi,
i have a typical one to many relationship between two tables:
Table_A: contains, for example, Stores (id, store_name)
Table_B: contains products, Prod, and which store the products
belong to: (id, name, store_id)
I need to create a query where i get all Store objects ordered by
the number
Hi Mariano, I tried your code and it worked great. Now I have to look
a way of linking the union query with a mapper to obtain a rather
elaborate object than a raw tuple, I mean, when you execute:
q = session.query(Computer).all()
you get Computer objects, but when you execute the union query you
Uff, sorry, the word-wrap destroyed my schema :(
Sandor
--
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to