Я думаю, что вы хотите left join
с фиксированным списком, если значения
select
d.windgroup,
count(s.reading_winddirection) cnt,
coalesce(round(
100 * count(s.reading_winddirection)
/ nullif(sum(count(s.reading_winddirection)) over(), 0)
), 0) percentage
from (
select 0 n, 'N' windgroup
union all select 1, 'NE'
union all select 2, 'E'
union all select 3, 'SE'
union all select 4, 'S'
union all select 5, 'SW'
union all select 6, 'W'
union all select 7, 'NW'
) d
left join simulation_readings s
on floor(s.reading_winddirection / 45) = d.n
group by d.windgroup
В MySQL <8.0, это будет выглядеть так: </p>
select
d.windgroup,
coalesce(c.cnt, 0) cnt,
coalesce(round(100 * c.cnt, 0 / nullif(t.total, 0)), 0) percentage
from (
select 0 n, 'N' windgroup
union all select 1, 'NE'
union all select 2, 'E'
union all select 3, 'SE'
union all select 4, 'S'
union all select 5, 'SW'
union all select 6, 'W'
union all select 7, 'NW'
) d
cross join (select count(*) total from simulation_readings) t
left join (
select floor(reading_winddirection / 45) n, count(*) cnt
from simulation_readings
group by n
) c on c.n = d.n
group by d.windgroup