3
如何将这样的东西翻译成SQLAlchemy?如何在SQLAlchemy中对算术表达式进行ORDER BY?
SELECT (a * b) - (x + y)/z AS result
FROM table
ORDER BY result
如何将这样的东西翻译成SQLAlchemy?如何在SQLAlchemy中对算术表达式进行ORDER BY?
SELECT (a * b) - (x + y)/z AS result
FROM table
ORDER BY result
作为一个字符串参数只需通过标签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")
使用`ORDER_BY = result_exp.name`也应该工作。 – kaka 2013-09-25 17:59:56