4
我在查詢過去30天內從我們的數據庫中獲取每天的構建數量。但是需要標記那些沒有構建的日子。MySql查詢幫助
在我的WHERE子句中,我使用submittime來確定是否有構建,我如何修改這個以包含COUNT(id)== 0但只在最近30天內的日子。
原始查詢:
SELECT COUNT(id) AS 'Past-Month-Builds',
CONCAT(MONTH(submittime), '-', DAY(submittime)) as 'Month-Day'
FROM builds
WHERE DATE(submittime) >= DATE_SUB(CURDATE(), INTERVAL 30 day)
GROUP BY MONTH(submittime), DAY(submittime);
我已經試過:
SELECT COUNT(id) AS 'Past-Month-Builds',
CONCAT(MONTH(submittime), '-', DAY(submittime)) as 'Month-Day'
FROM builds
WHERE DATE(submittime) >= DATE_SUB(CURDATE(), INTERVAL 30 day)
OR COUNT(id) = 0
GROUP BY MONTH(submittime), DAY(submittime);
聽起來就像是問題是,你沒有的日期在'builds'表 - 看看其他'的datetime-generation'標記爲問題的例子。 –