[sqlalchemy] Re: column label and order by

2009-11-17 Thread rajasekhar911
anyone?? On Nov 14, 6:48 pm, rajasekhar911 rajasekhar...@gmail.com wrote: Hi guys, how do i apply order by on a column with a label. My requirement is like this class x   id,   amount,   date i have to group based on id and take sum of amount within a date range. i am applying a

[sqlalchemy] Re: column label and order by

2009-11-17 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of rajasekhar911 Sent: 17 November 2009 11:32 To: sqlalchemy Subject: [sqlalchemy] Re: column label and order by anyone?? On Nov 14, 6:48 pm, rajasekhar911 rajasekhar

[sqlalchemy] Re: column label and order by

2009-11-17 Thread Mike Conley
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

[sqlalchemy] Re: column label and order by

2009-11-17 Thread rajasekhar911
session.query( func.sum(x.amount).label('tot_amount'), x.id ). filter(x.datefromdate).filter(x.datetodate). .group_by(x.id) .order_by('tot_amount DESC') .limit(5) On Nov 17, 4:55 pm, Mike Conley mconl...@gmail.com wrote: And you do need to quote the column name in order_by also.