Hi all,
I have a table which looks like this:
id | t_stamp
--------------------------------
1110 | 2010-05-16 12:02:18
1111 | 2010-05-16 12:12:45
1122 | 2010-05-16 12:12:06
1122 | 2010-05-16 12:13:45
1122 | 2010-05-16 12:17:52
1122 | 2010-05-16 12:18:08
1121 | 2010-05-16 12:20:33
1121 | 2010-05-16 12:21:23
1110 | 2010-05-16 12:21:36
1110 | 2010-05-16 12:23:56
1121 | 2010-05-16 12:33:49
1110 | 2010-05-16 12:35:51
1136 | 2010-05-16 12:47:10
1133 | 2010-05-16 12:48:09
1137 | 2010-05-16 12:49:10
1133 | 2010-05-16 12:53:09
Assume that this data is captured for interval one hour, from 12:00:00 to 13:00:00.
first, i want select all duplicate id for interval one hour, for every 30mins, and for every 15mins.
For one hour, the data should look like this:
id | t_stamp
--------------------------------
1110 | 2010-05-16 12:02:18
1110 | 2010-05-16 12:21:36
1110 | 2010-05-16 12:23:56
1110 | 2010-05-16 12:35:51
1121 | 2010-05-16 12:20:33
1121 | 2010-05-16 12:21:23
1121 | 2010-05-16 12:33:49
1122 | 2010-05-16 12:12:06
1122 | 2010-05-16 12:13:45
1122 | 2010-05-16 12:17:52
1122 | 2010-05-16 12:18:08
1133 | 2010-05-16 12:48:09
1133 | 2010-05-16 12:53:09
For every 30 minutes, select duplicate id.
id | t_stamp
--------------------------------
1110 | 2010-05-16 12:02:18 }
1110 | 2010-05-16 12:21:36 }
1110 | 2010-05-16 12:23:56 }
1121 | 2010-05-16 12:20:33 }
1121 | 2010-05-16 12:21:23 } 1st 30 minutes (1-30)
1122 | 2010-05-16 12:12:06 }
1122 | 2010-05-16 12:13:45 }
1122 | 2010-05-16 12:17:52 }
1122 | 2010-05-16 12:18:08 }
---------------------------------
1133 | 2010-05-16 12:48:09 } 2nd 30 minutes (30-60)
1133 | 2010-05-16 12:53:09 }
For every 15 minutes, select duplicate id
id | t_stamp
--------------------------------
1122 | 2010-05-16 12:12:06 } 1st 15 minutes (1-15)
1122 | 2010-05-16 12:13:45 }
---------------------------------
1122 | 2010-05-16 12:17:52 }
1122 | 2010-05-16 12:18:08 }
1110 | 2010-05-16 12:21:36 }
1110 | 2010-05-16 12:23:56 } 2nd 15 minutes (15-30)
1121 | 2010-05-16 12:20:33 }
1121 | 2010-05-16 12:21:23 }
---------------------------------
} 3rd 15 minutes (30-45)
---------------------------------
1133 | 2010-05-16 12:48:09 } 4th 15 minutes (45-60)
1133 | 2010-05-16 12:53:09 }
for 1 hour, i can do with:
Code:
SELECT id, t_stamp FROM log
WHERE id IN (SELECT id FROM log GROUP BY id HAVING COUNT(*)>1) AND t_stamp
BETWEEN date_trunc('hour',current_timestamp - interval '1 hour')
AND date_trunc('hour',current_timestamp)
Now, i try to do for every 30minutes and 15 minutes but if i do something like -interval '30 minutes', this will only show data for the first 30 minutes.
Help me to figure this out. thank u very much.
Regards,
nbtet