Skip to content Skip to sidebar Skip to footer

How To Divide Two Columns In Sqlalchemy

How generate this SQL, with sqlalchemy SELECT SUM(click) / SUM(impression) as my_indicator FROM stats; session.query( func.sum(table.click).label('click'), func.sum(table.

Solution 1:

from sqlalchemy.sql import label

session.query(
    label('my_indicator', sum(click) / sum(impression))
).group_by(table.type)

Post a Comment for "How To Divide Two Columns In Sqlalchemy"