python - sqlite:断言语句:获取具有最高值的名称

标签 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'

最佳答案

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

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

关于python - sqlite:断言语句:获取具有最高值的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52525895/

相关文章:

python - UFCNN 值错误 : when checking model input

python - 根据键的组合比较字典

mysql - 如何将变量插入Sqlite3数据库

sqlite - 在SQLite中为全文搜索索引创建SQL触发器

python - 为什么我的类(class)会引发 AttributeError?

python - 如何动态更新Python循环中参数的值?

python - 具有缺失值的列子集的逐行平均值

android - ContentProvider 数据库未被删除

mysql - 交叉加入 SQLite 与其他数据库

javascript - 无法访问cordova SQLite存储插件