sqlite:断言:获取具有最高价值的名称

时间:2018-09-26 20:53:34

标签: python sqlite

注意:请随时共享适用的资源。我发现这很困难。

我正在尝试编写以下python函数:

def player_with_max_points_per_game():
    """ The player with highest average points per game"""

    cur.execute('SELECT name, avg_points FROM players ORDER BY 
    avg_points')

    # Now I want to select 'name' from the top row

PS:我意识到我的预期方法可能效率不高。我看到有一个MAX()函数。有什么建议吗?

Here is an image from my DB browser sorted by 'avg_points'

1 个答案:

答案 0 :(得分:0)

只需获取第一列的值即可。

cur.execute('SELECT name, avg_points FROM players ORDER BY avg_points DESC LIMIT 1')
row = cur.fetchone()
best_player_name = row[0]