我有一张有学生信息的表格,现在我想知道男女学生的人数。使用普通 SQL 我可以使用它
select student_gender, count(student_gender) from student_registration group by student_gender;
经过一番小搜索,我在 SQLAlchemy 中发现了以下等价性
gender = db.session.query(Student_Registration.student_gender, \
func.count(Student_Registration.student_gender))\
.group_by(Student_Registration.student_gender).all()
现在我想打印所需的输出。使用
for b in gender:
print(b.student_gender)
如何打印计数?我试过 b.count 但它显示
Female <built-in method count of result object at 0x7fac60f21240>
Male <built-in method count of result object at 0x7fac60f21288>