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

发布于 2024-12-23 17:31:26 字数 208 浏览 0 评论 0原文

我在此查询中遇到错误,

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;

I am getting error in this query,

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雾里花 2024-12-30 17:31:26

这个怎么样:

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;

How about this:

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;
萌梦深 2024-12-30 17:31:26

只是快速猜测,无需检查 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;

Just a quick guess without checking nagios schema

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文