So I am querying a database that is called golfDB and it consists of one table called players with 5 fields:
- name (player's name)
- totalGross (sum of the gross scores from each round)
- totalRounds (number of rounds played)
- pars (total number of pars made)
- birdies (total number of birdies made)
The function I'm working on is supposed to list the players in descending order according to their average score (totalGross/ totalRounds).
I'm not entirely sure how to go about doing this, my code is currently separating all the components (players, total gross score, and total rounds) into their own lists. I was thinking then I could divide each total gross score list item by each item in the total rounds list, but I'm not really sure how to then link those scores back to their corresponding player so that they can be ordered.
I don't know if it is even possible to do it this way, so does anyone have any suggestions or ideas?
def queryDBplayers(cursor):
"""lists the players in order of their total gross score"""
cursor.execute('select name, totalGross, totalRounds from players')
answer= cursor.fetchall()
players = list()
for items in answer:
players.append(items[0])
totalGrossScore = list()
for items in answer:
totalGrossScore.append(items[1])
totalRoundsScore = list()
for items in answer:
totalRoundsScore.append(items[2])