Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:12:58+00:00 2026-06-18T11:12:58+00:00

I want to group the data in a table by time interval. The table

  • 0

I want to group the data in a table by time interval. The table keeps the order info that includes the userid, item name, model, quantity, activity date, etc. Now I want to group this data by time intervals. The time interval could be anything like 5 min, 10 min, 15, etc. Also, the query should return only those users (all the column data) who made orders more than once within that 5 minutes interval. Is it possible to achieve this in one SQL query? I use Oracle.

Thank you

Edit:

Sample data

**userid    item name    model      quantity   order date**
abc calculator   cdm83ss    1      02-FEB-2013 09:20:13     
abc alarm clock  actp001    1      02-FEB-2013 09:26:22
yyy iPhone       iP4    1      02-FEB-2013 09:28:14
abc alarm clock  actz321    2      02-FEB-2013 09:30:00
zzz backpack     bp344tk    1      04-FEB-2013 13:15:00
zzz backpack     bp234zz    2      04-FEB-2013 13:19:32
zzz camera       cm234  1      04-FEB-2013 13:20:22 
ttt tv       fs45yup    1      04-FEB-2013 13:28:19

I expect to get:

**userid    item name    model      quantity   order date**
abc         calculator   cdm83ss    1      02-FEB-2013 09:20:13     
abc         alarm clock  actp001    1      02-FEB-2013 09:26:22
abc         alarm clock  actz321    2      02-FEB-2013 09:30:00
zzz         backpack     bp344tk    1      04-FEB-2013 13:15:00
zzz         backpack     bp234zz    2      04-FEB-2013 13:19:32
zzz         camera       cm234  1      04-FEB-2013 13:20:22 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:13:00+00:00Added an answer on June 18, 2026 at 11:13 am

    Yes. Presumably you want to see the result as a datetime value as well. This requires some datetime arithmetic. Basically, getting the number of minutes since midnight, dividing by the number of minutes and then multiplying again (to round down). Then adding back in the time at midnight:

    select t.*
    from (select t.*,
                 count(*) over (partition by userid, interval) as CntInInterval
          from (select trunc(orderdate)+
                       (floor(((orderdate - trunc(orderdate))*24*60)/10)*10)/(24*60) as interval, t.*
                from t
               ) t
         ) t
    where cntInInterval > 1
    

    To group by time intervals, you would use:

          select interval, count(*)
          from (select trunc(orderdate)+floor(((orderdate - trunc(orderdate))*24*60)/10)*10 as interval, t.*
                from t
               ) t
          group by interval
    

    In these queries, “10” stands for any number of minutes. Note that these are calculated since midnight, so a value like 17 always starts with the first 17 minutes of the day.

    The definition of interval is an arithmetic expression on dates.

              trunc(orderdate)+floor(((orderdate – trunc(orderdate))*24*60)/10)*10 as interval,

    The first part, trunc(orderdate), is Oracle syntax for removing the time part of a date. This moves the date to midnight at the beginning of the day.

    The expression orderdate - trunc(orderdate) calculates the number of days since midnight — this is a fractional part of one day. So, 0.25 would be 6:00 a.m. The *24*60 converts this to minutes. So, 0.25 becomes 0.25*60*24 = 360 — the number of minutes since midnight.

    Then the expression floor(x/y)*y simply “truncates” any value to the lower multiple of y. So, floor(118/10) is 11, and 11*10 is 110. In other words, this will map all values between a*y and (a+1)*y (up to not including) to the same value, a*y.

    Consider the expression in practice, on 6:08 a.m. on 2013-01-01:

    `trunc(orderdate)` moves the date to midnight on 2013-01-01.
    `orderdate - trunc(orderdate)` creates a number like 0.25.
    `((orderdate - trunc(orderdate))*24*60)` produces the value 368
    `floor(((orderdate - trunc(orderdate))*24*60)/10)*10` produces 360
    `floor(((orderdate - trunc(orderdate))*24*60)/10)*10*(1/24*60)` produces 0.25
    

    And when this is added to minight, the time turns into 6:00 a.m. again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that has various attributes and I want to hierarchically group
I have some data pollution in a table that I'm having a hard time
I want to implement some code in excel macro to group some data for
I want to group every date that it is in the database and get
I want to group results of query by the item id and count number
Let's say I have a table with the following data. Table name [Data]. PrimaryID:
I have a Table that stores data on price movement over a minute. Each
I'm trying to build a query that will order results by date and time,
A short description: I have a table with data that is updated over a
I want to group my data by the hour/day possibly even to the quarter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.