[sqlalchemy] Re: order_by() and count()

2010-02-08 Thread gsandorx
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())

[sqlalchemy] order_by() and count()

2010-02-04 Thread gsandorx
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

[sqlalchemy] Re: Multiple table query ?

2009-12-22 Thread gsandorx
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

[sqlalchemy] Re: Multiple table query ?

2009-12-21 Thread gsandorx
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