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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:24:08+00:00 2026-06-05T05:24:08+00:00

I have a mysql table A which stores a sequence of numbers and timestamps

  • 0

I have a mysql table A which stores a sequence of numbers and timestamps

value    timestamp
12087    2012-01-01 00:00:00
12110    2012-01-02 02:00:00
12223    2012-01-04 03:00:00
12312    2012-01-04 05:00:00
12387    2012-01-04 06:00:00
12388    2012-01-05 01:11:23
...

The both values and timestamps are ordered: the greater timestamp the greater value, but there is no other dependency between them.

I need to find the greatest difference between values in sorted sequence for a period. In the example the differences are:

12110-12087=23
12223-12100=13
12312-12223=89
12387-12312=75
12388-12387=1

So we have the greatest difference 89.

The question is: how to code SQL query for that? Do know, that I don’t want to use full product and/or correlated queries since the table is enormous.

  • 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-05T05:24:10+00:00Added an answer on June 5, 2026 at 5:24 am
    select 
        (case when (@prev is null) then 0
        else abs(value - @prev) end) as diff
      , concat(value, '-', @prev)
      , @prev := value
    
        from (select value, dt from table1 order by dt) ordered
        order by diff limit 1
    

    add the period restrictors into the from subquery

    edit, new info tells me this is an unreliable method
    http://dev.mysql.com/doc/refman/5.0/en/user-variables.html (ctrl + f for SELECT @a, @a:=@a+1)

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

Sidebar

Related Questions

I have a MYSQL-Table which stores scores. Every time a user improves a new
I have a MySql table called reviews which stores a lot of product reviews,
I have a mysql table field set as time type which stores data in
I have a table in mysql which stores (among other columns) a bitmask as
I have an order table in MySQL database, having a field/column which stores the
I have a MYSQL table which stores teams. Table structure: CREATE TABLE teams (
I have a database table (MySQL 5) which stores file hashes and filenames. I
I have a table with column timestam which stores a timestamp with this format:
$value = 'http://www.mydomain.com/this-is-page-one' I have a field in my mysql table called urls which
I have a mysql table which stores about 5000 products. I then query the

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.