如何在SQLAlchemy中按顺序运算?

时间:2008-12-16 00:16:41

标签: python sqlalchemy

如何将这样的内容翻译成SQLAlchemy?

SELECT (a * b) - (x + y) / z AS result
FROM table
ORDER BY result

1 个答案:

答案 0 :(得分:3)

只需将标签作为字符串参数传递给order_by

result_exp = sqlalchemy.sql.expression.label('result',
   ((test2_table.c.a * test2_table.c.b)
    - (test2_table.c.x + test2_table.c.y)
    / test2_table.c.z))
select([result_exp], from_obj=[test2_table], order_by="result")