我使用flask作为python框架和sqlalchemy。该机型采用query_property,帮助我建立查询:sqlalchemy group_by和count
class Person(object):
query = db_session.query_property()
....
persons = Person.query.all()
每个人都有一个城市,州和国家,在那里他住在我要收集所有的结果和类似:
Country State City Persons(count)
================================================================================
US NY New York 10
DE Berlin Berlin 100
这显然需要按国家,州,市选择计数和分组。以物组工作,但我不知道如何实现计数,因为查询属性在这种情况下,我会写不会选择方法:
Person.query.select([Person.country, Person.state, Person.city, func.count(Person.id)]).all()
任何一个想法如何使用query_property与GROUP_BY和计数?