I have a table which is randomly generated. It has 3 columns : P_Id, date (at which the row was inserted) and text. Let’s say the text can be various animals. So the table could look like
1 2011-06-15 03:04:05 cow
2 2011-06-15 03:04:15 dog
3 2011-06-15 03:04:19 bird
4 2011-06-15 03:04:30 cow
5 2011-06-15 03:04:30 dog
6 2011-06-15 03:04:35 cow
....
What is a query to pick all animals that have occurred at least twice within the last 30 minutes of its latest entry? For eg, here cow occurs 3 times within the last 30 minutes of its latest entry, which is at 3:04:35, and dog has occurred twice. Bird would not be selected as it only occurred once.
There’s always the straight forward way (i.e. use a subquery to extract the timestamp range and then proceed as usual):