如何将此sql转换为sqlalchemy查询? (年,月,在QQ中计数)

时间:2015-02-19 03:57:25

标签: mysql sql sqlalchemy

如何将此sql转换为sqlalchemy代码?

SELECT YEAR(post.released_time), MONTH(post.released_time), COUNT(*) \
FROM post GROUP BY YEAR(post.released_time) AND MONTH(post.released_time)

感谢您的帮助^ _ ^!

1 个答案:

答案 0 :(得分:2)

终于解决了〜

db.session.query(sqlalchemy.func.year(Post.released_time), sqlalchemy.func.month(Post.released_time), sqlalchemy.func.count('*')).\
group_by(sqlalchemy.func.year(Post.released_time), sqlalchemy.func.month(Post.released_time)).all()