Hi, I was looking to find out how i can do a count based on date and timestamps. I currently have the following data and I would like to do a count on the different timestamps but for a rolling 30 minute period.
AgentĀ | Date_1
Joe Bloggs | 15-jun-16 13:09:00
Joe Bloggs | 15-jun-16 13:09:00
Joe Bloggs | 15-jun-16 13:29:00
Joe Bloggs | 15-jun-16 13:55:00
Joe Bloggs | 16-jun-16 11:11:00
I have written the following query:
SELECT
TRUNC(DATE_1) AS DATE_1
ROW_NUMBER() OVER (PARTITION BY AGENT, TRUNC(DATE_1) ORDER BY DATE_1) AS COUNT_1
FROM TABLE_1
and this gives me:
Agent | Date_1 | Count_1
Joe Bloggs | 15-jun-16 | 4
Joe Bloggs | 16-jun-16 | 1
but what i would like is that the first 2 rows have the same date/time so this counts 1 and then the 3rd row is at 13:29 so within 20 mins so count stays 1, but the fourth row shows a value of 13:55 which is 30 mins after the first row so this will now count 2.
Results should be:
Agent | Date_1 | Count_1
Joe Bloggs | 15-jun-16 | 2
Joe Bloggs | 16-jun-16 | 1
Would appreciate if somebody could please advise on how i can get round this issue.
Thanks in advance.