session.query( func.sum(x.amount).label('tot_amount'), x.id ).
filter(x.date>fromdate).filter(x.date<todate).
.group_by(x.id)
.order_by('tot_amount DESC')
.limit(5)

On Nov 17, 4:55 pm, Mike Conley <[email protected]> wrote:
> And you do need to quote the column name in order_by also.
>
> session.query(func.sum(X.amount).label('tot_amount')).group_by(X.date).order_by('tot_amount').limit(10)
>
> generates code
>
> SELECT sum(x.amount) AS tot_amount
> FROM x GROUP BY x.date ORDER BY tot_amount
>  LIMIT 10 OFFSET 0
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to