4
Description: Count how many times the action occurred in the night period considering the time from 18:00 to 06:00 in the morning.
There is a better way to select this type without having to use or to compare periods?
select count(*) as contador,log_desc,'Noite' from log
where extract(hour from log_data_hora)>=0 and extract(hour fromlog_data_hora)<6
or extract(hour from log_data_hora)>18 and extract(hour from log_data_hora)<=23
group by log_desc,cor_cod
I am using Postgresql.
Using this BETWEEN would take the whole period(cunning,late) and I want only the night period, corresponding from 18 hours until 6 am.
– Andrew Alex
@Andrewalex Hence the use of denial (NOT). The expression above reads: 'Return all records where the time is NOT between 6 and 17', which would cover until 17:59.
– OnoSendai
Correct now worked. Simple and functional.
– Andrew Alex