我有以下查询需要在sqlalchemy中工作:
SELECT
l_date,
(select sum(sub_fct.baseline) from fct_table as sub_fct where l_date <= main_fct.l_date ) AS inc_base,
(select sum(sub_fct.actual) from fct_table as sub_fct where lunch_date <= main_fct.lunch_date ) AS inc_actual
FROM
fct_table AS main_fct
我试图弄清楚这一点,并陷入了困境。
inc_base = db.session.query(func.sum(Fact.baseline))
inc_actual = db.session.query(func.sum(Fact.actual))
query = db.session.query(Fact.l_date, inc_base.label('inc_base'), inc_actual.label('inc_actual'))
这当然给了我列中所有值的静态和,而且我不知道如何传递
Fact.l_date
从主查询到子查询中过滤器的值。