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

  • Home
  • SEARCH
  • 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 9321193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:48:28+00:00 2026-06-19T03:48:28+00:00

I have a large database I use for plotting and data examination. For simplicity,

  • 0

I have a large database I use for plotting and data examination. For simplicity, say it looks something like this:

|    id    |    day    |    obs    |
+----------+-----------+-----------+
|    1     |    500    |    4.5    | 
|    2     |    500    |    4.4    | 
|    3     |    500    |    4.7    | 
|    4     |    500    |    4.8    | 
|    5     |    600    |    5.1    | 
|    6     |    600    |    5.2    | 
                ...

This could be stock market data, where we have many points per day that are measured.

What I want to do is look at much longer trends, where the multiple points per day are unnecessarily resolved, and clog my plotting application. (I want to look at 30000 days, each has about 100 observations).

Is there a way to do something like SELECT ... LIMIT 1 PER "day"

I suppose I could perform a few SELECT DISTINCT queries to find correct ID’s, but I’d rather do something simple if it is built in.

It doesn’t matter if its the first, last, or an average value per day. Just a single value. I just prefer what is fastest.

Also, this I’d like to do this for Postgres, MySQL, and SQLite. My application is built to use all three and I frequently switch between them.

Thanks!

Background: This is for a Ruby on Rails plotting application, so a trick with ActiveRecord will work too. https://github.com/ZachDischner/Rails-Plotter

  • 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-19T03:48:29+00:00Added an answer on June 19, 2026 at 3:48 am

    You need to tag your question with the brand of RDBMS you’re using. Frequently for Rails developers, they’re using MySQL, but the answer to your question depends on this.

    For all brands except for MySQL, the correct and standard solution is to use windowing functions:

    SELECT * FROM (
      SELECT ROW_NUMBER() OVER (PARTITION BY day) AS RN, *
      FROM stockmarketdata
    ) AS t
    WHERE t.RN = 1;
    

    For MySQL, which doesn’t support windowing functions yet, you can simulate them in a kind of clumsy way with session variables:

    SELECT * FROM (SELECT @day:=0, @r:=0) AS _init,
    (
      SELECT IF(day=@day, @r:=@r+1, @r:=0) AS RN, @day:=day AS d, *
      FROM stockmarketdata
    ) AS t
    WHERE t.RN = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large readonly Wordnet PostgreSQL database that I'd like to use from
I have one large database table of request data, much like Apache request logs,
We have a large database with a lot of data in it. I found
I have a large database and am putting together a report of the data.
I have large set of data(more than 1TB). This will be accessed by more
I have a large database of normalized order data that is becoming very slow
I am trying to import data from a large database. I have two tables
I have a large database containing more than five million records, this database has
I have a large quantity of data in a production database that I want
I have a large database of locations, all with lat/long. I use GeoKit and

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.