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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.