1
I’m doing a consultation in postgres, but it only brings the results where the inspection body is not reset, I needed this query to bring all the results from 8 to 18, including zeroes:
AS YOU BRING:
HOW YOU WANTED ME TO BRING:
QUERY:
select (
date_trunc('hour', data)
) intervalo_data,
count(id) fiscalizacoes
from fiscalizacoes
where data >= '2019-06-21 08:00:0.000000'
and data <= '2019-06-21 18:00:00.000000'
group by intervalo_data
order by intervalo_data;
are using
date_trunc
in select but grouping with the normal date? it doesn’t look like it will work as expected, you have to let the group by equal to select– Ricardo Pontual
The grouping is working, I executed and returned what I expected, even because I have to bring the number of inspections per 1 hour interval, from 8 to 18.
– Gabriel Becher
It’s not that it’s not working, but it groups for the whole date without truncating hours. There are all these hours that is not returning, for example 11:00:00?
– Ricardo Pontual
Grouped by date_trunc('hour', date) and continues with the same result, not ignoring the results
– Gabriel Becher
but if not group, there is record in the hours that are missing?
– Ricardo Pontual
does not exist, is this my question, if I have to return 0 for the hours that have no instance.
– Gabriel Becher
ah now I understand :)
– Ricardo Pontual