8
class Employee
id
name
class Location
id
city
class Work
id
employee_id
location_id
TODO:左移计数连接(包括零)SQLAlchemy的左连接与计数
期望的结果
location.city count
NYC 10
SFO 5
CHI 0
原始查询:
select location.id, count(work.id) as count
from location
left join work
on location.id = work.location_id
group by location.id
的SQLAlchemy:
db_session.query(Location, func.count.work_id).label('count')). \
filter(location.id == work.location_id). \
group_by(location._id). \
在进行左连接时,在select中指定列的正确方法是什么?