SQL语句中的汇总+取最大值

2025-03-28 20:29:28
推荐回答(1个)
回答(1):

可以这样写SQL语句:

select a.name,a.game,
b.g as TotalGameTime from
(select name,game,sum(duration) as gs
from tblName group by name,game) a,
(select name,max(gs) as g from (select name,game,sum(duration) as gs
from tblName group by name,game)
group by name) b where a.name=b.name
and a.gs=b.g;