MySQL统计用户创建了多少条记录

MySQL count how many records has user made

我正在计算唯一玩家 [auth] 创造了多少记录。 所以基本上我正在尝试 select 每张地图上的最短时间并计算谁剩下最多的条目。

我通过大量谷歌搜索走到了这一步。

SELECT
    auth,
    map,
    MIN(time) AS Record
FROM
    bhop.playertimes
WHERE track LIKE '0'
GROUP BY
    map
)

这成功列出了每张地图的最高时间和 [auth] 创造记录的人。 对 [auth] 条目求和的最简单方法是什么?

我更喜欢这种类型的回答查询:

[授权] [records_made]

我想你想要:

select p.auth, count(*) no_records
from bhop.playertimes p
where 
    p.track = 0
    and p.time = (
        select min(p1.time) 
        from bhop.playertimes p1 
        where p1.map = p.map and p1.track = 0
    )

这为您提供了每个 authmap 数量,他们拥有最短时间(据我了解,这是您对 auth 的定义 记录).

如果你是运行 MySQL 8.0,你可以用window函数得到相同的结果 rank():

select auth, count(*) no_records
from (
    select auth, rank() over(partition by map order by time) rn
    from bhop.playertimes
    where track = 0
) p
group by auth