MySQL Forums
Forum List  »  Newbie

Incress Number
Posted by: Raphael ottiger
Date: November 18, 2021 08:43AM

Hello everyone

I need your help.
At the moment i work with mysql.

My database contains two fields: kilometers and reading time.

I get the kilometers every 15 minutes from an odometer.

This number is steadily increasing. Now I want the difference for one day in the last 30 days.


My idea now is that I filter the highest value of the following day (last value) with the highest value of the current day and then subtract today's value with yesterday's. And that over the last 30 days, which gives me a table with 30 values.

Now I wrote two queries:

ReadDate = Datatime


This ist for der highest Value per day:
--------------------------------------
SELECT ReadDate, max(kilometers)FROM `MeasurementKilometers`
where zaehlerId = 1
GROUP by ReadDate

And this is my Query for the diffrent between the ID's:
--------------------------------------
Select a.messungId, a.Kilometers - b.Kilometers AS diff From MeasurementKilometers a left Join MeasurementKilometers b
ON
a.ReadDate -1 = b.ReadDate


Now I have to combine these two queries, how do I do this? Or do you recommend another approach?

Have a nice day.

Options: ReplyQuote


Subject
Written By
Posted
Incress Number
November 18, 2021 08:43AM
November 18, 2021 09:17AM
November 19, 2021 07:18AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.