我有一个表,其中包含不同仓库列的库存。 我需要找出符合以下条件的记录。它是一个mysql数据库。
统计多列总和等于0的记录数。
表的结构
Stock A | Stock B | Stock C | Stock D
0 | 1 | 0 | 0
0 | 0 | 0 | 0
1 | 1 | 1 | 1
这里的输出将为 1。
最佳答案
这应该相当简单:
create table test (stock_a int, stock_b int, stock_c int, stock_d int);
insert into test values (0,1,0,0), (0,0,0,0), (1,1,1,1);
select count(*) from test where stock_a + stock_b + stock_c + stock_d = 0
Result:
count(*)
--------
1
关于php - 统计mysql表中多列总和等于0的记录条数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32632825/