我正在尝试为某些游戏策略创建“顶部”

桌子是这样的

mapname     authid  country     name    time    date    weapon  server


我有这个查询,我认为很好(显示每张地图的最短时间)

SELECT name, min( time ) AS time
FROM kz_pro15
GROUP BY mapname ASC


我正在得到结果

name    time
Santaaa     907.75
Zimmek*     184.82
:d  34.35
waldoo  1.04
Epiphany    8.54
Lovvon  185.51
Epiphany    64.53
menqz   73.67
waldoo  93.97
KoLkkE  207.83
q[o__o]p    78.35
Ulysses gc     T! CS    154.01
sasuke FTW  151.17
sasuke FTW  41.62
Santaaa     80.38
Santaaa     196.95
JonyBu  135.56
tiBU    93.12
Santaaa     122.04
Santaaa     36.08
EzzeqL  149.14
Zeqqe   106.75
bondiO^     110.68
INJUNABLES  102.09
Sublime     72.15
Player  106.11
=(M4t1ttU)=     158.95
foo conscience  80.98
gabe    27.21
gabe    58.5


但是现在我要计算结果,以获取之前列出的球员有多少条记录

gabe      2
sublime   1
player   13

最佳答案

除非name依赖mapname,否则您的查询不正确:

SELECT name, min( time ) AS time
FROM kz_pro15
GROUP BY mapname ASC


它将为每个MIN(time)显示mapname,但不能保证将在最短的时间内显示相关的name

改用它(并注意子查询):

SELECT k.name
     , COUNT(*) AS cnt
FROM kz_pro15 AS k
  JOIN
    ( SELECT mapname
           , MIN(time) AS time
      FROM kz_pro15
      GROUP BY mapname
    ) AS g
    ON (g.mapname, g.time) = (k.mapname, k.time)
GROUP BY k.name

09-19 11:23