0

我有 mysql 数据库。

我正在运行以下查询。

SELECT cluster,
       infra_properties.property_name property,
       count(*)
FROM   raw_alerts,
       infra_properties
WHERE  infra_properties.parent_group = raw_alerts.cluster
       AND cluster = 'abuse-content'
       AND infra_properties.property_name = 'BigBro'
       AND timestamp BETWEEN '2012-12-24 00:00:00' AND '2012-12-24 23:59:59'
GROUP  BY cluster; 

我的输出为空,但我的要求是计数=0。如下所述。

+---------------+----------+----------+
| cluster       | property | count(*) |
+---------------+----------+----------+
| abuse-content | BigBro   |    0     |
+---------------+----------+----------+
1 row in set (0.30 sec)
4

1 回答 1

0

如果 2 个表上没有匹配的记录,则不会返回任何行。

您可能需要做的是有一个带有集群和属性列的额外表,然后执行以下操作:-

SELECT a.cluster, a.property, count(c.id)
    FROM SomeExtraTable a
    LEFT OUTER JOIN raw_alerts b ON a.cluster = b.cluster AND AND b.cluster = 'abuse-content'
    LEFT OUTER JOIN infra_properties c 
ON a.property = c.property 
AND c.parent_group = b.cluster
AND c.property_name = 'BigBro' 
AND c.timestamp BETWEEN '2012-12-24 00:00:00' AND '2012-12-24 23:59:59'
    GROUP  BY  a.cluster, a.property

(我只是猜测时间戳列在哪个表上)

于 2013-02-22T11:46:21.840 回答