On 4/19/15 9:56 AM, Mike Bayer wrote:

On 4/19/15 9:36 AM, ThereMichael wrote:

    Sorry, sometimes you get so deep into something you forget
    everyone else isn't familiar with the problem.


As an example, here's what I'm looking for:

select things.id, count(comments.type) from things things, comments comments where things.creation >= "2015-04-19" and things.creation < "2015-04-26" and comments.target_id = things.id
and comments.type = 5
and comments.creation >= "2015-04-19" and comments.creation < "2015-04-26"
group by things.id
order by count(comments.type) desc;


s = Session()
q = s.query(Thing.id, func.count(Comment.type)).\
    filter(Thing.creation >= datetime.date(2015, 4, 19)).\
    filter(Thing.creation < datetime.date(2015, 4, 26)).\
    filter(Comment.target_id == Thing.id).\
    filter(Comment.creation >= datetime.date(2015, 4, 19)).\
    filter(Comment.creation < datetime.date(2015, 4, 26)).\
    group_by(Thing.id).\
    order_by(func.count(Comment.type).desc())
one more filter for the Comment.type:

q = s.query(Thing.id, func.count(Comment.type)).\
    filter(Thing.creation >= datetime.date(2015, 4, 19)).\
    filter(Thing.creation < datetime.date(2015, 4, 26)).\
    filter(Comment.target_id == Thing.id).\
    filter(Comment.creation >= datetime.date(2015, 4, 19)).\
    filter(Comment.creation < datetime.date(2015, 4, 26)).\
    filter(Comment.type == 5).\
    group_by(Thing.id).\
    order_by(func.count(Comment.type).desc())



--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to