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 8608743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:41:41+00:00 2026-06-12T03:41:41+00:00

I need to group stockmarket 1min data with {Name, DateTime, Open, High, Low, Close,

  • 0

I need to group stockmarket “1min” data with {Name, DateTime, Open, High, Low, Close, Volume} into different timeframes ie. “5mins/15mins/60mins” on MYSQL. Schema built on sqlfiddle – http://sqlfiddle.com/#!2/91433.

I found a link – Group OHLC-Stockmarket Data into multiple timeframes with T-SQL with similar requirement for MSSQL.

I tried to follow the link – http://briansteffens.com/2011/07/19/row_number-partition-and-over-in-mysql/, to get row_number(), over, partition in mysql to solve the issue.

I am a newbie to sql, can anyone please point me in the right direction?

  • 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-12T03:41:43+00:00Added an answer on June 12, 2026 at 3:41 am

    Finally resolved the issue with the following mysql query:

    select min(a.mydate),max(a.myhigh) as high,min(a.mylow) as low, 
    min(case when rn_asc = 1 then a.myopen end) as open,
    min(case when rn_desc = 1 then b.myclose end) as close
    
    from( 
    
    select 
    @i := if((@lastdate) != (Floor(unix_timestamp(mydate)/300 )), 1, @i + 1) as rn_asc,
              mydate, myhigh, mylow, myopen, myclose,
              @lastdate := (Floor(unix_timestamp(mydate)/300 ))
    
    from
      onemindata_1,
      (select @i := 0) vt1,
      (select @lastdate := null) vt2 order by mydate
    
    ) a
    
    inner join(
    
    select 
    @j := if((@lastdate1) != (Floor(unix_timestamp(mydate)/300 )), 1, @j + 1) as rn_desc,
              mydate,myclose,
              @lastdate1 := (Floor(unix_timestamp(mydate)/300 ))
    
    from
      onemindata_1,
      (select @j := 0) vt1,
      (select @lastdate1 := null) vt2 order by mydate desc
    
    )b
    on a.mydate=b.mydate
    group by (Floor(unix_timestamp(a.mydate)/300 ))
    

    Toughest part was to get the Open and Close for the “Specific Time Intervals”. I am doing an inner join of ‘high,low,open’ with ‘close’ on ‘date’. I can switch the time intervals by changing the denominator in (Floor(unix_timestamp(mydate)/300 )). Currently not worried about the performance as long as it works :).

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

Sidebar

Related Questions

I need to group the data in my indexed array of indexed arrays by
I have a skewed data set and I need to do a group by
Following is the sample data set that I need to group together, if you
I need to Group my Table into 15 minutes Intervals. I can do that
I have the following data table and i need to group it by quarters.
Hi i need group the records based on the time stmap datetime column 2011-11-23
I need to group the data in my 2d array by the SiteId column
I need to group data from my 2d array by one column and sum
I need to group data held in a list but can’t hardcode the groupBy
I'm running into the not-so-well-documented conundrum where you need to GROUP BY and ORDER

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.