我使用的是查询:
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查询只返回一个玩家,日期,维生素; 对于具有最近日期的每个不同玩家?
我希望我的输出为:
# player date, vit
-----------------------------------------------
'Greenslade', '2016-01-12 14:07:47', '1208252'
'Pheresis', '2016-01-12 14:04:01', '924164'
我该怎么做?
答案 0 :(得分:2)
您只需要汇总:
select player, max(date), max(health_base + mana_base * 2) as vit
from t
group by player
order by vit desc;