Jump to content

Group within a certain time period?


sciencebear

Recommended Posts

I have a certain table, updates, with columns id, user, type, date, and time. I am trying to group them and get a count of how many in each group by user, type, and within a certain time period. However, I can't seem to get the last part to work. I can group them by user, type and day with the following query:

 

SELECT *,COUNT(type) FROM updates GROUP BY user,type,date ORDER BY id DESC

 

However, like I said, I need to do the same thing except narrow down the time frame. The problem is that I can't just do "GROUP BY user,type,time" because that would only do updates at the exact same second. I want to group updates that are the same user and type and about 30 minutes apart. Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/194249-group-within-a-certain-time-period/
Share on other sites

Thanks! I had to change it a little because of the way my table was set up (date and time in separate columns) but the below code works great. Thank you very much!

 

SELECT *, COUNT(type)
FROM updates
GROUP BY
   user,type,date,
   ((60/30) * HOUR(time) + FLOOR(MINUTE(time) / 30))
ORDER BY id DESC

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.