Hi I’d like to calculate number of batch running instance for a particular time slice. For example, I’ve a table:
BatchID startTime endTime
12957 10:15 10:25
13032 10:16 10:20
13080 10:16 10:22
13090 10:16 10:20
13214 10:19 10:30
13232 10:19 10:22
13276 10:19 10:29
13279 10:19 10:30
13315 10:20 10:23
13341 10:20 10:24
13430 10:22 10:33
13566 10:27 10:30
13580 10:27 10:31
13585 10:28 10:31
13596 10:28 10:32
13626 10:30 10:42
13637 10:32 10:35
13699 10:40 10:44
13702 10:41 10:45
The number of instance running at 10:41 would be 3, and the running batches are: BatchID 13626, 13699 and 13702.
To visualise this problem, I have a chat with a time slice from 10:15 to 10:41 with a step of 1 minutes as the x-axis,and the number of instance running at that time slice as the y-axis. I’m thinking to implement in ORACLE(SQL/PLSQL) or EXCEL(function/VBA/Pivot Table/etc.), what’s your advise?
Creating your sample table:
Introducing the start and the end of the interval you want to report on, as bind variables. You can recognize the use of bind variables in SQL and PL/SQL by their leading colons.
And a query that’s executed in three phases for sake of clarity. First transforming your varchar2 times to real dates (advice is to store them like that as well, by the way). The second query shows all minutes on the X-axis for your report. The third one does the counting.
EDIT: I just saw your comment that your columns are stored as dates. That’s good news, so you can skip the first part and start with line number 7, replacing the comma with the word “WITH”.
Regards,
Rob.