2
The SQL below brings the number of entries made month by month, until then blz. I needed to show the last 6 months, even if it was zero, but in this select it would only bring when there are records.
select
extract(month from data_cad) as mes,
count(*) as qtd
from mv_clientes
where (ativo not in('C'))
and (data_cad between '2017-12-01' and '2018-05-31')
group by 1
I am using Mysql, but do not know comes to the case, I could see SQL on another basis and translate pro Mysql
The result of this SQL is this
mes qtd
3 | 5
4 | 8
5 | 23
I needed you to be:
mes qtd
12 | 0
1 | 0
2 | 0
3 | 5
4 | 8
5 | 23
Maybe you can use something like that to generate the months, and then make a left Join with your table.
– hkotsubo
Possible duplicate of How to set to zero or null in an SQL query of a date range, for those whose value does not exist?
– Diego Rafael Souza
In this question of Maniero some alternative suggestions were also presented.
– Diego Rafael Souza
If I click "This solved my problem" the stack will withdraw the answer I selected as solution below?
– Marcelo