我想做一个负责从PostgreSQL数据库中检索数据的查询。
我已经构建了一个PostgreSQL查询,它在Pgadmin上运行良好。但我不确定如何使用SQLAlchemy转换此查询。
SELECT SUM(click) as click,
SUM(nSignup) as nsignup,
SUM(nDepo) as ndepo,
SUM(valDepo) as valdepo,
SUM(numDepo) as numdepo,
SUM(spotsTurn) as spotsturn,
SUM(commission) as commission,
EXTRACT(YEAR FROM myDate)::text || EXTRACT(MONTH FROM dateto)::text || EXTRACT(WEEK FROM myDate)::text AS datefield
FROM bet365s
GROUP BY datefield
ORDER By datefield;
如果我使用SQLAlchemy,我认为上面的查询应该如下转换。
但我不确定如何使用SQLAlchemy转换此查询。
db.session.query(Bet365, func.sum(Bet365.click), func.sum(Bet365.nsignup), func.sum(Bet365.ndepo), \
func.sum(Bet365.valdepo), func.sum(Bet365.numdepo),func.sum(Bet365.spotsturn), func.sum(Bet365.commission), \
func.year(Bet365.myDate )....)
我想知道我该怎么做。