0
The rule
All records that are within a 1 hour interval should be counted as 1 records only.
Dice
ID DATA
1 06/07/2017 09:20:35
2 06/07/2017 10:20:35
3 06/07/2017 10:25:30
4 06/07/2017 10:40:35
5 06/07/2017 10:50:35
6 06/07/2017 11:25:30
7 06/07/2017 11:50:20
8 06/07/2017 15:25:30
9 06/07/2017 17:25:30
10 06/07/2017 17:30:30
11 06/07/2017 17:40:55
Expected result
count data
5 06/07/2017
Why? Why from the earliest date, records that are "within" up to one hour after that date, count as 1 only. More or less that:
count range_data
1 09:20:35 - 10:20:35
1 10:20:36 - 11:20:36
1 11:20:37 - 12:20:37
0 12:20:38 - 13:20:38
0 13:20:39 - 14:20:39
0 14:20:40 - 15:20:40
1 15:20:41 - 16:20:41
1 17:20:42 - 18:20:41
Any suggestions for doing this? Not with interactivity (for/while). Because I can have N dates in the middle, I don’t have a "standard" of minimum and maximum dates... the only thing I know is that the dates are within the same day.
I don’t want to have to make N selects to count between hour and hour...
I think at least you will have to adopt the standard hours of 00:00 M:S to 59:59 Minutes:Seconds. in your example you have 09:20:35 - 10:20:35, it becomes very variable since there is no beginning or end to start/finish.
– Marco Souza
"There’s no" and there’s at the same time... The point is to always take the smallest date and the biggest... and come up with a logic to do everything in the same query rs
– Marllon Nasser
you mean in that case the shortest date is 9:20:35 and counts 1 hour after that to the end, and then searches the next hour and counts another hour to the end and so on.
– Marco Souza
Yes... my shortest date can be at 07:15:00, for example...is always 1 hour from it...until the longest date. got it?
– Marllon Nasser
I think you could use something like that. The numbers are meaningless and need to be adjusted to your reality. select min( id ), case when ( date >= getdate() - 20 or data <= getdate() - 30 ) then 'yesterday' when ( date >= getdate() or date <= getdate() - 4 ) then 'today' when ( date >= getdate() + 12 or date <= getdate() - 20 ) then 'tomorrow' end as data from test group by data
– Reginaldo Rigo
@Marllonnasser, got it , you need to show the total and the intervals of hours?
– Marco Souza
I need one total per DAY. In short lines, for each interval I have record, I increment my counter.
– Marllon Nasser
THE BASE WOULD BE SOMETHING LIKE SELECT TO_CHAR(SYSDATE,'DD/MM/YY HH24:MI:SS') FULL, TO_CHAR(TRUNC(SYSDATE,'HH24'),'DD/MM/YY HH24:MI:SS') TRUNCATED FROM DUAL FULL TRUNCATED ---------------------------------------------------------------------------
– Motta