如何在MySQL中使用“COUNT”条件?

时间:2012-01-02 05:31:57

标签: mysql count

我在此查询中收到错误

SELECT count(if(state=0)) FROM `nagios`.`nagios_hostchecks`
where `nagios_hostchecks`.`start_time` like '%2012-01-02%'
and `nagios_hostchecks`.`host_object_id`=60;

2 个答案:

答案 0 :(得分:3)

快速猜测而不检查nagios架构

SELECT count(*) FROM nagios.nagios_hostchecks
WHERE state=0 AND nagios_hostchecks.start_time like '%2012-01-02%' 
AND nagios_hostchecks.host_object_id=60;

答案 1 :(得分:3)

这个怎么样:

SELECT count(*) 
FROM `nagios`.`nagios_hostchecks` 
WHERE `nagios_hostchecks`.`start_time` like '%2012-01-02%' 
    AND 
`nagios_hostchecks`.`host_object_id`=60
    AND
`state` = 0;
相关问题