如何将这样的内容翻译成SQLAlchemy?
SELECT (a * b) - (x + y) / z AS result
FROM table
ORDER BY result
答案 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")