> -----Original Message----- > From: sqlalchemy@googlegroups.com > [mailto:sqlalch...@googlegroups.com] On Behalf Of Hollister > Sent: 20 June 2009 02:15 > To: sqlalchemy > Subject: [sqlalchemy] Re: aggregation with count and > webhelpers.paginate > > > Well, that worked great: > > q = meta.Session.query(m.Hit.referer, func.count(m.Hit.id))\ > .group_by(m.Hit.referer)\ > .order_by(func.count(m.Hit.id).desc()) > > Thanks! > > ps: Is there a better way to specify the count in the order_by? >
If it's just that you don't like repeating yourself, you should be able to save the result of func.count (untested): hit_count = func.count(m.Hit.id) q = (meta.Session.query(m.Hit.referer, hit_count) .group_by(m.Hit.referer) .order_by(hit_count.desc()) Simon --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---