如何将此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)
感谢您的帮助^ _ ^!
答案 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()