好的,我有一个带有W
or的列L
来指定输赢。我想统计所有的输赢,得到一个胜率。
SELECT banner_name, count(win_loss) as wins
FROM drop_log
where win_loss = 'W'
group by banner_name
这给了我所有的球队以及他们有多少胜利。我将如何调整它以使另一列用于损失,另一列用于比率。MySQL 似乎具有与 SQL Server 2008 不同的语法规则。
好的,我有一个带有W
or的列L
来指定输赢。我想统计所有的输赢,得到一个胜率。
SELECT banner_name, count(win_loss) as wins
FROM drop_log
where win_loss = 'W'
group by banner_name
这给了我所有的球队以及他们有多少胜利。我将如何调整它以使另一列用于损失,另一列用于比率。MySQL 似乎具有与 SQL Server 2008 不同的语法规则。
SELECT banner_name, SUM(IF(win_loss = "W", 1, 0)) AS wins,
SUM(IF(win_loss = "L", 1, 0)) AS losses
FROM drop_log
GROUP BY banner_name
You may also be able to get the percentage in this way, but it's easy to divide after the selection too.
It would also be better to use a boolean (0
or 1
) to designate a win or loss, but this would work in pretty much the same way.
EDIT: It would actually work to simply use SUM(win_loss = 'letter')
as this will return 1
or 0
already.
这将为您提供所需的所有 3 个值。
SELECT banner_name, wins, total-wins AS losses, wins/total AS win_ratio
FROM (select banner_name, SUM(win_losses = 'W') AS wins, COUNT(*) AS total
FROM drop_log
GROUP BY banner_name) w