Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Count()中指定条件?_Php_Mysql_Count - Fatal编程技术网

Php 如何在Count()中指定条件?

Php 如何在Count()中指定条件?,php,mysql,count,Php,Mysql,Count,我只想计算状态为0的行 示例a_no列的状态为0,其计数为1 这是我的问题 select date, count(DISTINCT no_a) as Transaction, CASE when status=0 then count(distinct no_a) end as Success from transfer_tx_201503 您可以指定计数之外的条件: select count(distinct no_a) as Transaction,

我只想计算状态为0的行 示例a_no列的状态为0,其计数为1

这是我的问题

select date, count(DISTINCT no_a) as Transaction, 
     CASE when status=0 then count(distinct no_a) end as Success
     from transfer_tx_201503

您可以指定计数之外的条件:

select 
    count(distinct no_a) as Transaction,
    count(distinct case status when 0 then no_a else -1 end case) - 1 as Success
from your_table
假设no_a是整数,并且值-1不是有效值,则这应该可以工作。
您只需将所有状态为非零的行放在一个bucket中,然后从计数中减去一即可。

为什么不使用简单的where子句?如果我使用where,它也会过滤事务,即我希望显示所有数字,即使状态为零=0所以您想同时计算状态为0的行和状态为Transaction否,我想计算状态为0的行和状态为成功的行的数量谢谢您的回答,但这不是我想要的。我希望计数状态仅在成功列中为0。如果使用where,事务也将遵循以下条件:您希望看到更新的内容-对状态为0的行进行计数?