class Employee
id
name
class Location
id
city
class Work
id
employee_id
location_id
Todo: Trái tham gia với số lượng (bao gồm zero)SQLAlchemy Left Tham gia với số lượng
kết quả mong muốn
location.city count
NYC 10
SFO 5
CHI 0
liệu Query:
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). \
Cách đúng để chỉ định các cột được chọn trong khi thực hiện một phép nối trái là gì?