php - 带条件的 MySQL 查询

标签 php mysql sql

我有一个 MySQL 表格:

    id | error 1 | error 2 | error 3 | error 4 |
    --------------------------------------------
     1 |    1    |    0    |    0    |    1    |
    -------------------------------------------
     2 |    0    |    0    |    0    |    0    |

id 是主键,errors 是 bool 列。 有没有一种方法可以获取行的 ID,如果任何错误为 1 为真,如果所有错误为零则为假。

最佳答案

select id,case when error1+error2+error3+error4 > 0
                then 1
                else 0
            end as error 
from Table t;

关于php - 带条件的 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28670992/

相关文章:

mysql - 嵌套选择不接受多于一列

mysql - 仅当它们在 MySQL 中一个接一个时,才对具有相同值的行进行分组

php - 获取特定日期范围内的文章数量

php - 如何在Laravel/Eloquent中使用字符串字段的一部分搜索记录?

php - mySql 返回不正确的结果

mysql - MySQL CPU 时间本来就这么长吗?

sql - SQL Server 中的事务管理和临时表

mysql - SQL 连接 with where 和having count() 条件

SQL on Spark : How do I get all values of DISTINCT?

php - 使用 php 将希伯来语 utf8 保存到数据库