Try it this way:
SELECT V.DataV
, IFNULL(COUNT(IF(axlNumber = 2, 1, NULL)), 0) AS eixos2
, IFNULL(COUNT(IF(axlNumber = 3, 1, NULL)), 0) AS eixos3
, IFNULL(COUNT(IF(axlNumber = 4, 1, NULL)), 0) AS eixos4
, IFNULL(COUNT(IF(axlNumber = 5, 1, NULL)), 0) AS eixos5
, IFNULL(COUNT(IF(axlNumber = 6, 1, NULL)), 0) AS eixos6
, IFNULL(COUNT(IF(axlNumber = 7, 1, NULL)), 0) AS eixos7
, IFNULL(COUNT(IF(axlNumber = 8, 1, NULL)), 0) AS eixos8
, IFNULL(COUNT(IF(axlNumber = 9, 1, NULL)), 0) AS eixos9
FROM (
SELECT ADDDATE('1970-01-01', t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) AS DataV
FROM (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t0
, (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t1
, (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t2
, (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t3
, (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t4
) V
LEFT JOIN tb_vbv ON DATE(tb_vbv.data) = V.DataV
WHERE V.DataV BETWEEN '2018/11/01' AND '2019/02/28'
AND tb_vbv.siteid = 20110
GROUP BY 1;
From what I understand you want all the dates of the interval regardless of whether they exist in the database. See this implementation of the generate_series function, existing in other DBMS, in Mysql: https://stackoverflow.com/questions/6870499/generate-series-equivalent-in-mysql and make an Outer Join with your table.
– anonimo
that’s right! thank you!!
– Leandro Kojima