def cherk(request):
'''# 查询学生总人数'''
# result =models.Student.objects.aggregate(Count("id"))
'''# 查询“生物”课程和“物理”课程成绩都及格的学生id和姓名;'''
# result = models.Course.objects.filter(Q(cname="生物") & Q(cname="物理"), score__score__gt=59).values(
# "score__student__saname")
'''# 查询每个年级的班级数,取出班级数最多的前三个年级;'''
# result =models.Class_grade.objects.values("gname").annotate(Count("class1__id")).order_by("gname")[:3]
'''5、 查询平均成绩最高的学生的id和姓名以及平均成绩;'''
# result = models.Score.objects.values("student_id", "student__saname").annotate(
# avg =Avg('score')
# ).order_by("avg")
"""6: 查询每个年级的学生人数; """
# result =models.Class_grade.objects.values("gname").annotate(Count("class1__student__id")).filter(gname="一年级")
# result =models.Class_grade.objects.values("gname").annotate(num=Count("class1__student__id")).filter(num=2)
"""
7、 查询每位学生的学号,姓名,平均成绩
"""
# result = models.Student.objects.annotate(avg1=Avg("score__score")).values("saname", "id","avg1")
"""
8、 查询学生编号为“2”的学生的姓名、该学生成绩最高的课程名及分数;
"""
# result =models.Student.objects.filter(id=2).annotate(max1=Max("score__score")).values("saname","max1")
"""
9、 查询姓“李”的老师的个数和所带班级数;
"""
# result =models.Teacher.objects.filter(tname__startswith="李").annotate(nnum=Count('tname'),cnum=Count("_classes__id")).\
# values("tname","nnum","cnum")
"""
10:查询班级数小于5的年级id和年级名;
"""
# result =models.Class1.objects.values("grade__gname").annotate(cap=Count("grade_id")).filter(cap__lt=2)
"""
11:查询教过课程超过2门的老师的id和姓名;
"""
# result =models.Teacher.objects.values("id","tname").annotate(num=Count("course__teacher_id")).filter(num__gt=1)
"""
12、查询学过编号“1”课程和编号“2”课程的同学的学号、姓名;
"""
# result =models.Student.objects.values("id","saname").filter(Q(score__course__id=1) & Q(score__course__id=2))
"""
13、查询所带班级数最多的老师id和姓名;
"""
# result =models.Teacher.objects.values("id","tname").annotate(Count("_classes"))
"""
14、查询有课程成绩小于60分的同学的学号、姓名;
"""
# result =models.Student.objects.values("id","saname","score__course__cname","score__score").filter(score__score__lt=60)
"""
15、查询男生、女生的人数,按倒序排列;
"""
# result =models.Student.objects.values("gender").annotate(manx=Count("gender")).order_by("manx").reverse()
"""
16、查询各个课程及相应的选修人数;
"""
# result =models.Course.objects.values("cname").annotate(Count("score__student__saname"))
"""
17、查询同时选修了物理课和生物课的学生id和姓名;
"""
# result =models.Student.objects.values("id","saname").filter(score__course__cname="生物")
"""
18检索“3”课程分数小于60,按分数降序排列的同学学号;
"""
# result =models.Course.objects.values("score__student__id").filter(Q(score__score__lt=60) & Q(cname="体育"))
"""
19、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列;
"""
# result =models.Course.objects.values("cname").annotate(num =Count("score__score")).order_by("num")
"""
20 查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分;
"""
result =models.Course.objects.values("cname").annotate(Max("score__score"),Min("score__score"))
print(result)
"""
"""
return HttpResponse("9999")
年与时驰,意与日去,遂成枯落,
多不接世,悲守穷庐,将复何及。