Optimize database queries for student training