两个模块写好
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from DoubaoTeam.schemas.statistics import NoExist
|
||||
from sqlalchemy import func
|
||||
|
||||
#`GET /statistics/students/age-over-30`
|
||||
#查询所有超过 30 岁的学员信息
|
||||
|
||||
def age_over_thirty(Student,db):
|
||||
student_list=db.query(Student).filter(Student.age>=30).all()
|
||||
if not student_list :
|
||||
raise NoExist('无目标年龄大于30岁')
|
||||
return student_list
|
||||
|
||||
def gender_count(Student,db):
|
||||
result=db.query(Student.class_id,Student.gender,func.count(Student.id)).group_by(Student.class_id,Student.gender).all()
|
||||
if not result :
|
||||
raise NoExist('班里招点人吧,要倒闭了')
|
||||
dict1 = {}
|
||||
for i,j,k in result:
|
||||
if i not in dict1 :
|
||||
dict1[i]={'男':0,'女':0}
|
||||
dict[i][j]+=k
|
||||
return dict1
|
||||
#查询每次考试成绩都在 80 分以上的学生编号、姓名和成绩
|
||||
def score_over_eighty(Score,Student,db):
|
||||
student_list=db.query(Student.id, Student.student_name)\
|
||||
.join(Student,Score.student_id==Student.id).group_by(Student.student_no,Student.student_name)\
|
||||
.having(func.min(Score.score)>80).all()
|
||||
for i in student_list:
|
||||
student_list2 = db.query(Student.student_no, Student.student_name,Score.score).join(Student,Score.student_id==Student.id).filter(i.id==Student.id).all()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user