[sqlalchemy] How to Use Alias in ORDER BY Caluse?

2013-01-07 Thread Ji Zhang
Hi, My SQL is like select host, count(*) as cnt from tbl group by host order by cnt desc How to achieve this using ORM? session.query(Tbl.host, func.count('*').label('cnt')).group_by(Tbl.host).order_by(???) I don't wanna type again func.count... in order_by(). Thanks. -- You received this

Re: [sqlalchemy] How to Use Alias in ORDER BY Caluse?

2013-01-07 Thread Michael Bayer
On Jan 7, 2013, at 9:19 PM, Ji Zhang wrote: Hi, My SQL is like select host, count(*) as cnt from tbl group by host order by cnt desc How to achieve this using ORM? session.query(Tbl.host, func.count('*').label('cnt')).group_by(Tbl.host).order_by(???) I don't wanna type again

Re: [sqlalchemy] How to Use Alias in ORDER BY Caluse?

2013-01-07 Thread Ji Zhang
The second one is neat. Thanks~ On Tuesday, January 8, 2013 11:28:34 AM UTC+8, Michael Bayer wrote: On Jan 7, 2013, at 9:19 PM, Ji Zhang wrote: Hi, My SQL is like select host, count(*) as cnt from tbl group by host order by cnt desc How to achieve this using ORM?