如何使用sqlalchemy生成此SQL
SELECT SUM(click) / SUM(impression) as my_indicator
FROM stats;
session.query(
func.sum(table.click).label("click"),
func.sum(table.impression).label("impression"),
# ??? sum(click) / sum(impression) ???
).group_by(table.type)
答案 0 :(得分:0)
from sqlalchemy.sql import label
session.query(
label('my_indicator', sum(click) / sum(impression))
).group_by(table.type)