【发布时间】:2011-03-12 08:40:12
【问题描述】:
我尝试执行的查询是this one。我已经把它贴在下面了:
SELECT p.id, p.title, p.time_submitted, SUM(v.score) as num_votes
FROM posts p, votes v
WHERE v.postid = p.id
GROUP BY p.id
ORDER BY
(SUM(v.score) - 1) / POW(TIMESTAMPDIFF(HOUR,p.time_submitted,NOW()) + INTERVAL 2 HOUR, 1.8) DESC
LIMIT 100
我打算使用connection.execute 手动运行 SQL 而不使用 ORM,但后来意识到它会在开发模式(金字塔)中失败,因为 sqlite 不支持使用的函数。
我将如何使用 ORM 执行此操作?
DBSession().query(Posts).join(Posts.id, Votes.post_id).group_by(Posts.id).order_by(...)
我不知道如何更进一步>.
【问题讨论】:
标签: python sql orm sqlalchemy