Image of the database I am working with...
我目前正在与NBA球员数据库一起练习。相关字段包括名称,活动和游戏。我正在尝试创建一个包含名称和 games_per_year(活动/游戏)的临时表。
首先,我过滤了原始数据库,筛选出我已经成功完成11年以上活动的玩家。
现在我不确定如何创建由名称和games_per_year组成的临时表。最终,我想按games_per_year排序此临时表,并返回前6名玩家的姓名。
这是我下面的编码尝试。如您所见,我有点迷路了...
def most_games_per_year_for_veterans():
"""Top 6 players that are > 10 years active, that have the
highest # games / year"""
player_list = cur.execute("SELECT name, active, games FROM players
WHERE active > 10").fetchall()
conn.execute('''CREATE TABLE IF NOT EXISTS active_vets
(name TEXT,
games_per_year REAL)''')
for player in player_list:
# Create a tuple? Just a guess...
player = (player[0], player[2]/ player[1])
cur.executemany('INSERT INTO active_vets VALUES (?,?)', player)
欢迎您提出批评,如果您有任何过去对您有所帮助的资源,我很乐意阅读。我发现很难在线找到所需答案。