0
我有mysql數據庫。如果查詢返回null,count = 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)
我跑了波紋管查詢,但仍然沒有運氣。選擇羣集,infra_properties.property_name屬性,COALESCE(COUNT(*),0)作爲從raw_alerts計數,infra_properties其中infra_properties.parent_group = raw_alerts.cluster和cluster ='abuse-content'和infra_properties.property_name ='BigBro'和時間戳之間'2013-1-24 00:00:00'和'2013-1-24 23:59:59'按羣組分組; – 2013-02-22 11:17:16
你嘗試過'count(cluster)'嗎? – tttthomasssss 2013-02-22 11:22:39
是的,已經試過了 – 2013-02-22 11:29:25