--select * from public."CertamenTabasco_calificacion"; SELECT sum(calificacion) calificaciones, participante_id , juez_id FROM public."CertamenTabasco_calificacion" where evento_id= 2 and ronda_id =1 group by participante_id, juez_id order by 1 desc ; -- python manage.py shell -- from CertamenTabasco.models import * -- c = Calificacion.objects.filter(evento_id=2, ronda_id=1).annotate(calificaciones=Sum('calificacion'), dcount=Count('participante')).order_by('-calificaciones')[:7] -- for x in c: --print x. --Calificacion.objects.values_list('participante_id').filter(evento_id=juez.evento.id, ronda_id=vr).order_by('id') --select participante_id from "CertamenTabasco_calificacion" where evento_id=2 and ronda_id = 12 order by id select count(juez_id) from public."CertamenTabasco_calificacion" group by juez_id ; --Calificacion.objects.values_list('juez_id').filter(juez_id=juez.id, evento_id=juez.evento.id, ronda_id=vr).order_by('id') select * from public."CertamenTabasco_calificacion" where juez_id=1 and evento_id=2 and ronda_id =2 ; select * from "CertamenTabasco_participante" where id in (8,9,15,5, 19,11, 18) select participante_id, sum(calificacion) from "CertamenTabasco_calificacion" where evento_id = 3 and ronda_id = 1 group by evento_id, participante_id order by 2 desc