I'm not sure I understand the link between student and student_class.  Does 
student.class_name reference class_name.id?

Anyway, I think you need to be joining things up properly, and grouping by 
student:

def generate_report():    

    marks=db(
      (db.student_class.class_name=='5A')
      & (db.student.class_name == db.student_class.id)
      & (db.marks.student == db.student.id)
    ).select(
      db.marks.avg().with_alias('average_marks'),
      groupby=db.marks.student,
      orderby=~db.marks.avg()
    )

    return locals()

Then you can find the position in the rowset.


On Thursday, 30 November 2017 10:27:09 UTC, mostwanted wrote:
>
>
>
> On Thursday, November 30, 2017 at 12:03:06 PM UTC+2, 
> tim.n...@conted.ox.ac.uk wrote:
>>
>> I think you need to give a bit more context.  What are your model 
>> definitions for db.student_class and db.marks?  Does each student have 
>> multiple rows in the marks table?
>>
>
>
>
> *THESE ARE MY MODEL DEFINITIONS:*I put up the only the ones i thought mat 
> be necessary here but if u need anything else please let me know 
>
>> db.define_table('student_class',
>>                 Field('class_name', requires=IS_NOT_EMPTY()),
>>                 Field('teacher', 'reference teacher'),
>>                 format='%(class_name)s')
>>
>> db.define_table('student',
>>                 Field('surname', requires=IS_NOT_EMPTY()),
>>                 Field('name', requires=IS_NOT_EMPTY()),
>>                 Field('photo', 'upload', requires=IS_NOT_EMPTY()),
>>                 Field('gender', requires=IS_NOT_EMPTY()),
>>                 Field('residence', requires=IS_NOT_EMPTY()),
>>                 Field('guardian', 'reference parent'),
>>                 Field('class_name', 'reference student_class'),
>>                 Field('dob', 'date', requires=IS_NOT_EMPTY()),
>>                 format='%(surname)s', migrate=False, false_migrate=True)
>>
>> db.define_table('marks',
>>                 Field('student', 'reference student'),
>>                 Field('subject', 'reference subject'),
>>                 Field('term', 'reference term'),
>>                 Field('marks', 'float', requires=IS_NOT_EMPTY()),
>>                 Field('total', 'float', requires=IS_NOT_EMPTY()),
>>                 Field('percentage','float', readable=False, writable=
>> False),
>>                 Field('average', 'float', readable=False, writable=False
>> ),
>>                 Field('grade', readable=False, writable=False),
>>                 Field('totalAverage', readable=False, writable=False),
>>                 Field('averageGrade', readable=False, writable=False),
>>                 Field('comments',type='text',requires=IS_NOT_EMPTY()))
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to