【发布时间】:2010-11-01 23:20:15
【问题描述】:
我已经编写了以下查询。
select distinct(table3.*),
(select count(*)
from table2
where table2.cus_id = table3.id) as count,
(select sum(amount)
from table2
where table2.cus_id = table3.id) as total
from table2,
table1,
table3
where table3.id = table2.cus_id
and table2.own_id = table1.own_id;
它查找列的总和和产生总和的行数以及来自另一个表的一些相关数据。 (如果您认为可以改进,请随时优化)
我需要将其转换为 SQLAlchemy,但不知道从哪里开始。如有任何建议,我将不胜感激。
【问题讨论】:
标签: python sql postgresql sqlalchemy