Assigning a rank within each subject won't be easy. For a start review
http://allenbrowne.com/ranking.html. Possibly a VBA custom function will be required for your situation.
For the average, do an aggregate query that groups by subject and uses aggregate Avg() function then include that query in another query to join to data. The aggregate query will have to include the same filter criteria as the final query. Alternatively, use DAvg() domain aggregate function in query or in textboxes. Each expression will need the same filter criteria.