mySQL计算表中每个ID的行数

发布于 2024-11-24 12:31:13 字数 945 浏览 1 评论 0原文

数据库架构

----------------------------------------------------------
| id | killed | killed_by | killed_uuid | killed_by_uuid |
----------------------------------------------------------

killedkilled_by 保存实体类型。例如。 “玩家”、“环境”、“生物”。没有具体细节。

killed_uuidkilled_by_uuid 是玩家参与杀戮时的用户 ID。

该表保存了我的游戏服务器上发生的击杀事件。每次击杀都存储在单独的行中,因此每个玩家没有总计。

我想为每个用户 ID 创建总计并根据它们创建排行榜。所以基本上,计算每个单独的 UserID 的行数。

我尝试使用

select killed_by_uuid, count(id)
from kills
where killed='999' AND killed_by='999'
group by killed_by_uuid
order by count(id) desc

999 作为属于玩家实体的 ID,而不是实际的 USERID。但我得到的只是一个结果集:

Array
(
    [0] => c676680f-98cb-4893-b1ba-ab5ab59fc272
    [killed_by_uuid] => c676680f-98cb-4893-b1ba-ab5ab59fc272
    [1] => 15
    [count(id)] => 15
)

Database schema

----------------------------------------------------------
| id | killed | killed_by | killed_uuid | killed_by_uuid |
----------------------------------------------------------

killed and killed_by hold the entity type. eg. "Player", "Environment", "Creature". No specifics.

killed_uuid and killed_by_uuid are the userID's if a player is involved in the kill.

This table holds kills that happens on my game server. Each kill is stored in a separate row so there are no totals for each player.

I want to create the totals for each userID and create a leaderboard from them. So basically, count the rows that for each separate UserID.

I have tried using

select killed_by_uuid, count(id)
from kills
where killed='999' AND killed_by='999'
group by killed_by_uuid
order by count(id) desc

999 being the ID that belongs to a player entity kill NOT an actual USERID. But all I get is a single result set:

Array
(
    [0] => c676680f-98cb-4893-b1ba-ab5ab59fc272
    [killed_by_uuid] => c676680f-98cb-4893-b1ba-ab5ab59fc272
    [1] => 15
    [count(id)] => 15
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹊巢 2024-12-01 12:31:13
select killer, count(killer) as total_kills
from kills
where killed='player' and killed_by not in (<list of environment ids>)
group by killer
order by total_kills desc, killer
select killer, count(killer) as total_kills
from kills
where killed='player' and killed_by not in (<list of environment ids>)
group by killer
order by total_kills desc, killer
清醇 2024-12-01 12:31:13
SELECT COUNT(*) FROM KILLS WHERE KILLED=? AND KILLED_BY NOT IN (?, ?, ?, ?, ?, ...)
SELECT COUNT(*) FROM KILLS WHERE KILLED=? AND KILLED_BY NOT IN (?, ?, ?, ?, ?, ...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文