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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:22:40+00:00 2026-05-29T06:22:40+00:00

I want to make a MySQL to get daily differential values from a table

  • 0

I want to make a MySQL to get daily differential values from a table who looks like this:

Date               | VALUE
--------------------------------
"2011-01-14 19:30" |   5
"2011-01-15 13:30" |   6
"2011-01-15 23:50" |   9
"2011-01-16 9:30"  |   10
"2011-01-16 18:30" |   15

I have made two subqueries. The first one is to get the last daily value, because I want to compute the difference values from this data:

SELECT r.Date, r.VALUE
    FROM table AS r
    JOIN (
    SELECT DISTINCT max(t.Date) AS Date
    FROM table AS t
    WHERE t.Date < CURDATE() 
    GROUP BY DATE(t.Date) 
    ) AS x USING (Date)

The second one is made to get the differential values from the result of the first one (I show it with “table” name):

SELECT Date, VALUE - IFNULL( 
    (SELECT MAX( VALUE ) 
    FROM table
    WHERE Date < t1.table) , 0) AS diff
    FROM table AS t1
    ORDER BY Date

At first, I tried to save the result of first query in a temporary table but it’s not possible to use temporary tables with the second query. If I use the first query inside the FROM of second one between () with an alias, the server complaints about table alias doesn’t exist. How can get a something like this:

 Date               | VALUE
 ---------------------------
 "2011-01-15 00:00" |   4
 "2011-01-16 00:00" |   6
  • 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-29T06:22:41+00:00Added an answer on May 29, 2026 at 6:22 am

    Try this query –

    SELECT
      t1.dt AS date,
      t1.value - t2.value AS value
    FROM
      (SELECT DATE(date) dt, MAX(value) value FROM table GROUP BY dt) t1
    JOIN
      (SELECT DATE(date) dt, MAX(value) value FROM table GROUP BY dt) t2
        ON t1.dt = t2.dt + INTERVAL 1 DAY
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I retrieve data from a mysql database. I want to make this data available
when i want to make a foreach($_SESSION['banners']->result() as $banner), i get this error: The
I want to create a table with data from mysql, but with some exceptions.
I am trying to get my code work. I want to make a mysql
i want to make my table can filtering in each column. i get client
I want make a bash script which returns the position of an element from
I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
Using MySQL & Java Script I want to make a mysql connection in Java
I want to get MySQL working with the system Python 2.7 in Mac OS
I want to make a compound query into MySQL. If the first part of

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.