gpt4 book ai didi

mysql,不同的和最新的

转载 作者:行者123 更新时间:2023-11-29 07:25:16 26 4
gpt4 key购买 nike

我正在使用查询:

SELECT distinct player, date, (health_base + mana_base * 2) as vit FROM dadb.player_attributes order by  vit desc

并得到以下结果:

# player       date,                   vit
-----------------------------------------------
'Greenslade', '2016-01-12 14:05:03', '1208252'
'Greenslade', '2016-01-12 14:05:04', '1208252'
'Greenslade', '2016-01-12 14:07:46', '1208252'
'Greenslade', '2016-01-12 14:07:47', '1208252'
'Pheresis', '2016-01-12 13:45:54', '924164'
'Pheresis', '2016-01-12 13:45:55', '924164'
'Pheresis', '2016-01-12 13:48:55', '924164'
'Pheresis', '2016-01-12 13:48:56', '924164'
'Pheresis', '2016-01-12 13:48:57', '924164'
'Pheresis', '2016-01-12 14:04:00', '924164'
'Pheresis', '2016-01-12 14:04:01', '924164'

我怎样才能让我的sql查询只返回一个玩家、日期、vit;对于每个具有最近日期的不同玩家?

我希望我的输出是:

# player       date,                   vit
-----------------------------------------------
'Greenslade', '2016-01-12 14:07:47', '1208252'
'Pheresis', '2016-01-12 14:04:01', '924164'

我该怎么做?

最佳答案

您只需要聚合:

select player, max(date), max(health_base + mana_base * 2) as vit
from t
group by player
order by vit desc;

关于mysql,不同的和最新的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34757959/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com