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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:33:19+00:00 2026-05-26T18:33:19+00:00

I have a more or less good working query (concerning to the result) but

  • 0

I have a more or less good working query (concerning to the result) but it takes about 45seconds to be processed. That’s definitely too long for presenting the data in a GUI.
So my demand is to find a much faster/efficient query (something around a few milliseconds would be nice)
My data table has something around 3000 ~2,619,395 entries and is still growing.

Schema:

num | station | fetchDate             | exportValue | error
1   | PS1     | 2010-10-01 07:05:17   | 300         | 0
2   | PS2     | 2010-10-01 07:05:19   | 297         | 0
923 | PS1     | 2011-11-13 14:45:47   | 82771       | 0

Explanation

  • the exportValue is always incrementing
  • the exportValue represents the actual absolute value
  • in my case there are 10 stations
  • every ~15 minutes 10 new entries are written to the table
  • error is just an indicator for a proper working station

Working query:

select
    YEAR(fetchDate), station, Max(exportValue)-MIN(exportValue)
from
    registros
where
    exportValue > 0 and error = 0 
group
    by station, YEAR(fetchDate)
order 
    by YEAR(fetchDate), station

Output:

Year | station | Max-Min
2008 | PS1     | 24012
2008 | PS2     | 23709
2009 | PS1     | 28102
2009 | PS2     | 25098

My thoughts on it:

  1. writing several queries with between statements like ‘between 2008-01-01 and 2008-01-02′ to fetch the MIN(exportValue) and between 2008-12-30 and 2008-12-31’ to grab the MAX(exportValue) – Problem: a lot of queries and the problem with having no data in a specified time range (it’s not guaranteed that there will be data)
  2. limiting the resultset to my 10 stations only with using order by MIN(fetchDate) – problem: takes also a long time to process the query

Additional Info:
I’m using the query in a JAVA Application. That means, it would be possible to do some post-processing on the resultset if necessary. (JPA 2.0)

Any help/approaches/ideas are very appreciated. Thanks in advance.

  • 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-05-26T18:33:19+00:00Added an answer on May 26, 2026 at 6:33 pm

    Adding suitable indexes will help.
    2 compound indexes will speed things up significantly:

    ALTER TABLE tbl_name ADD INDEX (error, exportValue);
    ALTER TABLE tbl_name ADD INDEX (station, fetchDate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title more or less says it all: I have a function which takes
I have a class that retrieves its memeber (more or less 10 members) from
I have an odd question that I have always thought about, but could never
I have a text file that contains more or less paragraphs. The text is
I have more or less been able to understand and implement all these concepts
I have some more or less linear data of the form: x = [0.1,
For some time i have been making more or less little games. One level
I have a variety of time-series data stored on a more-or-less georeferenced grid, e.g.
I have the following code in a c++ listener class (more or less), which
I have more than one Event Listener that calls a specific function, and I

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.