[sqlalchemy] Re: How to query data from a relational table according to a list of matched conditions?

2009-12-23 Thread Gunnlaugur Briem
You can put the func.count() label in a variable and filter on it: articlecount = func.count(Article.id).label('count') for article in session.query(Article, articlecount) \ .join(Article.keywords).group_by(Article.name) \ .filter(Keyword.name.in_(['k2', 'k3', 'k6',

[sqlalchemy] Re: How to query data from a relational table according to a list of matched conditions?

2009-12-23 Thread Olli Wang
Hi, I tried it but got an OperationalError: '(OperationalError) misuse of aggregate: count(articles.id)' error. Any idea? Traceback (most recent call last): File relation.py, line 92, in module .order_by(articlecount.desc()): File

Re: [sqlalchemy] Re: How to query data from a relational table according to a list of matched conditions?

2009-12-23 Thread Michael Bayer
Gunnlaugur Briem wrote: You can put the func.count() label in a variable and filter on it: articlecount = func.count(Article.id).label('count') for article in session.query(Article, articlecount) \ .join(Article.keywords).group_by(Article.name) \

[sqlalchemy] Re: How to query data from a relational table according to a list of matched conditions?

2009-12-23 Thread Olli Wang
Oh, thanks. Works like a charm. :) Olli On Dec 23, 11:26 pm, Michael Bayer mike...@zzzcomputing.com wrote: Gunnlaugur Briem wrote: You can put the func.count() label in a variable and filter on it: articlecount = func.count(Article.id).label('count') for article in session.query(Article,

[sqlalchemy] Re: How to query data from a relational table according to a list of matched conditions?

2009-12-22 Thread Olli Wang
Thanks for reply. I finally got the right result as following: for article in session.query(Article, func.count(Article.id).label ('count')) \ .join(Article.keywords).group_by(Article.name) \ .filter(Keyword.name.in_(['k2', 'k3', 'k6', 'k7'])).order_by('count DESC'):