I am trying to think of the most efficient way to count specific rows in a MySQL table.
My table contains a datetime
column called date_time
and I want to count the number of rows where there is at least 30 minutes between each date_time
.
For example, lets say I have the table below:
id date_time
1 2013-08-23 00:30:00
2 2013-08-23 00:45:00
3 2013-08-23 01:01:00
4 2013-08-23 02:30:00
5 2013-08-23 02:45:00
If I only want to include an entry if there is at least 30 minutes since the last entry, then the count would include id #1 and id #4, thus the count would be 2.
I am trying to come up with a clean script to do this, is there any special kind of query that will help me accomplish this?