I justed read this page: In SQL, how can you "group by" in ranges?
The response helped me but I have a question, If the count() for a range equals 0, the range will not showed, how can I show the range when the count() equals to 0 ?
Here is my query:
select
w.Période,
nb from( select t.Période, count(*) as nb
from (select
*,
case
when report.creation_date between '2017-05-28 00:00:00' and '2017-06-25 00:00:00'
then 'P3'
when report.creation_date between '2017-06-25 00:00:00' and '2017-07-23 00:00:00'
then 'P4'
when report.creation_date between '2017-07-23 00:00:00' and '2017-08-20 00:00:00'
then 'P5'
when report.creation_date between '2017-08-20 00:00:00' and '2017-09-17 00:00:00'
then 'P6'
else 'Avant'
end as Période
from report
where report.office_id = 11) as t
group by t.Période ) as w
Here is my result:
Avant 57
P3 1
P5 2
P6 4
I would like to have:
Avant 57
P3 1
P4 0
P5 2
P6 4
I have tried to use these but it doesn't work. case when count() is null then 0 else count() end as nb or case when count() = 0 then 0 else count() end as nb or case when count() REGEXP '[^[:digit:]]' then 0 else count() end as nb