[英]I want print the value from sqlalchemy query of an aggreate function in python-flask
result_1 = Attendance.query.with_entities(Attendance.month, Attendance.year, Attendance.emp_id, func.count(Attendance.status)).filter(and_(Attendance.month == month, Attendance.year == year, Attendance.status == 'Present')).group_by(Attendance.emp_id,Attendance.month,Attendance.year).all()
#print(len(result_1))
for r in result_1:
print(r.month)
print(r.year)
print(r.emp_id)
#print(r.count)
Here I can print all the month,year, id values but how can i print the value of count?在这里我可以打印所有的月、年、id 值,但是如何打印计数的值?
Try this.. use .label()
to give the column a name and then use it later试试这个.. 使用.label()
为列命名,然后稍后使用
result_1 = Attendance.query.with_entities(Attendance.month, Attendance.year, Attendance.emp_id, func.count(Attendance.status).label('status_count'))
.filter(and_(Attendance.month == month, Attendance.year == year, Attendance.status == 'Present'))
.group_by(Attendance.emp_id,Attendance.month,Attendance.year).all()
for r in result_1:
print(r.month)
print(r.year)
print(r.emp_id)
print(r.status_count)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.