SELECT sector.sector, count(*)
FROM reports, organization, sector
WHERE reports.org_id = organization.id
AND organization.id = sector.org_id
GROUP BY sector.sector;
I'm honestly not even sure where to begin expressing this GROUP BY and JOIN in sqlalchemy.
db.query(func.count(Sector.sector), Sector.sector).\
join(Organzation).join(Report).\
group_by(Sector.sector).all()
I was able to represent it as the following expression. My earlier efforts were failing because I needed to db.rollback() my awkward failed attempts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With