视图.py
class MaxMarks(generics.ListAPIView):
queryset = Marks.objects.raw('select student_id, subject_id,
sem_marks, id, internal_marks, MAX(total_marks) from
collegedetails.college_marks ')
serializer_class = MarksSerializers
在映射到 URL 模式并开始运行服务器后,我正在尝试使用 views.py 中的原始函式计算最大标记,但它只获得一条记录,但仍有更多记录具有最大标记,有人可以建议我该怎么做吗?
uj5u.com热心网友回复:
SELECT t1.student_id,
t1.subject_id,
t1.sem_marks,
t1.id,
t1.internal_marks,
total_marks
FROM collegedetails.college_marks t1
JOIN ( SELECT MAX(t2.total_marks) total_marks
FROM collegedetails.college_marks t2 ) t3 USING (total_marks);
0 评论