统计该数据集上的查询结果

发布于 2024-12-24 00:56:29 字数 954 浏览 0 评论 0原文

使用以下查询:

$result = mysql_query(
"SELECT Stats.champion
FROM Stats, Games
WHERE Stats.game_id = Games.game_id
AND Stats.win = 1
AND Games.game_mode = 'ODIN'");

我返回以下数据集:

Ezreal 
Garen 
Pantheon 
Ahri 
Sion 
Rammus 
Nidalee 
Poppy 
Heimerdinger 
Graves 
KogMaw 
Gangplank 
Tristana 
Fizz 
Pantheon 
Pantheon 
Evelynn 
MasterYi 
Tryndamere 
Leona 
Vayne 
Malphite 
Graves 
Shaco 
Nidalee 
Graves 
Heimerdinger 
Gangplank 
JarvanIV 
Akali 

我的目标是计算每个名称的结果。我知道,例如“万神殿”,我可以这样做:

$result = mysql_query(
"SELECT Stats.champion
FROM Stats, Games
WHERE Stats.game_id = Games.game_id
AND Stats.champion = 'Pantheon'
AND Stats.win = 1
AND Games.game_mode = 'ODIN'");

$pantheonwins = mysql_num_rows($result);
echo $pantheonwins;

这会产生正确的信息!

Pantheon 
Pantheon 
Pantheon 
3

那么,既然这给了我正确的数据,那么这是获取每个名字的获胜计数,然后获取计算机百分比的记录总数的最有效方法吗?

with the following query:

$result = mysql_query(
"SELECT Stats.champion
FROM Stats, Games
WHERE Stats.game_id = Games.game_id
AND Stats.win = 1
AND Games.game_mode = 'ODIN'");

I am returned the following dataset:

Ezreal 
Garen 
Pantheon 
Ahri 
Sion 
Rammus 
Nidalee 
Poppy 
Heimerdinger 
Graves 
KogMaw 
Gangplank 
Tristana 
Fizz 
Pantheon 
Pantheon 
Evelynn 
MasterYi 
Tryndamere 
Leona 
Vayne 
Malphite 
Graves 
Shaco 
Nidalee 
Graves 
Heimerdinger 
Gangplank 
JarvanIV 
Akali 

My goal is to count the result for each name. I know for one, for example "Pantheon", I can do:

$result = mysql_query(
"SELECT Stats.champion
FROM Stats, Games
WHERE Stats.game_id = Games.game_id
AND Stats.champion = 'Pantheon'
AND Stats.win = 1
AND Games.game_mode = 'ODIN'");

$pantheonwins = mysql_num_rows($result);
echo $pantheonwins;

This results with the correct information!

Pantheon 
Pantheon 
Pantheon 
3

So since this gives me the correct data, is this the most efficient way to get the win count for each individual name, then get a total number of records to computer percents?

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

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

发布评论

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

评论(3

难得心□动 2024-12-31 00:56:29

尝试将您的查询更改为:

SELECT
    Stats.champion,
    count(Stats.champion) as myCount
FROM
    Stats, Games
WHERE 
    Stats.game_id = Games.game_id
    AND Stats.win = 1
    AND Games.game_mode = 'ODIN'
GROUP BY
    Stats.champion

现在,您应该在查询结果中获得计数以及champion

Try changing your query to this:

SELECT
    Stats.champion,
    count(Stats.champion) as myCount
FROM
    Stats, Games
WHERE 
    Stats.game_id = Games.game_id
    AND Stats.win = 1
    AND Games.game_mode = 'ODIN'
GROUP BY
    Stats.champion

Now, you should get the count along with the champion in the query result.

姜生凉生 2024-12-31 00:56:29
SELECT Stats.champion, COUNT(*) as aCount
FROM Stats, Games
WHERE Stats.game_id = Games.game_id
AND Stats.win = 1
AND Games.game_mode = 'ODIN'
GROUP BY Stats.champion
SELECT Stats.champion, COUNT(*) as aCount
FROM Stats, Games
WHERE Stats.game_id = Games.game_id
AND Stats.win = 1
AND Games.game_mode = 'ODIN'
GROUP BY Stats.champion
彩扇题诗 2024-12-31 00:56:29

怎么样:

SELECT Stats.champion
FROM Stats, Games
    WHERE Stats.game_id = Games.game_id
    AND Stats.champion = 'Pantheon'
    AND Stats.win = 1
    AND Games.game_mode = 'ODIN'
UNION
SELECT COUNT(Stats.champion) as champion
FROM Stats, Games
    WHERE Stats.game_id = Games.game_id
    AND Stats.champion = 'Pantheon'
    AND Stats.win = 1
    AND Games.game_mode = 'ODIN'

会返回,

Champion 
=============
Pantheon 
Pantheon 
Pantheon 
3

但如果你想得到这样的结果:

Champion       |        Result
==============================
Pantheon       |            3

那么你应该使用这个:

SELECT STATS.champion as Champion, COUNT(GAMES.game_id) as `Result`
FROM Stats INNER JOIN Games ON  Stats.game_id = Games.game_id
WHERE Stats.win = 1 AND Games.game_mode = 'ODIN'
GROUP BY Champion

how about this:

SELECT Stats.champion
FROM Stats, Games
    WHERE Stats.game_id = Games.game_id
    AND Stats.champion = 'Pantheon'
    AND Stats.win = 1
    AND Games.game_mode = 'ODIN'
UNION
SELECT COUNT(Stats.champion) as champion
FROM Stats, Games
    WHERE Stats.game_id = Games.game_id
    AND Stats.champion = 'Pantheon'
    AND Stats.win = 1
    AND Games.game_mode = 'ODIN'

will return

Champion 
=============
Pantheon 
Pantheon 
Pantheon 
3

but if you want to have results like this:

Champion       |        Result
==============================
Pantheon       |            3

then you should used this:

SELECT STATS.champion as Champion, COUNT(GAMES.game_id) as `Result`
FROM Stats INNER JOIN Games ON  Stats.game_id = Games.game_id
WHERE Stats.win = 1 AND Games.game_mode = 'ODIN'
GROUP BY Champion
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文