gpt4 book ai didi

Mysql查询输赢统计

转载 作者:行者123 更新时间:2023-11-29 12:56:13 26 4
gpt4 key购买 nike

我有一个包含一些列的表。其中一列记录该行是真还是假。例如,如果您输了游戏,则设置为 0,否则设置为 1。

我想计算的是行中1的数量。该表如下所示:

+-----------+
|game_status|
|-----------|
|00000000 |
|-----------|
|00000000 |
|-----------|
|00000001 |
|-----------|
|00000001 |
|-----------|
|00000001 |
|-----------|
| ... |
+-----------+

所以如果你用手数的话,结果将是:从0开始:

lost(0) ->  0 - 1 =
lost(0) -> -1 - 1 =
won(1) -> -2 + 1 =
won(1) -> -1 + 1 =
won(1) -> 0 + 1 =

结果 = 1

那么如何使用 mysql 查询得到这个结果呢?我尝试过使用 count,但它计算的是所有 1 或 0。

提前致谢。

我认为当我接受答案时我有点困惑,对此我深表歉意。我想我忘了说的是查询的结果应该是这样的:

+--------+------+
| 1 | -1 |
|--------|------|
| 2 | -2 |
|--------|------|
| 3 | -1 |
+---------------+

增量列是玩过的游戏数量...

最佳答案

您可以计算获胜次数并减去失败次数。

select (select count(status) from table1 where status = 1) - 
(select count(status) from table1 where status = 0)

关于Mysql查询输赢统计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24025348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com