MySQL Forums
Forum List  »  General

Calculate sum between rows when time changes
Posted by: Marco Singh
Date: March 01, 2015 02:09PM

Hi,

I have a database table which looks as follows:

id Name timestamp Value1 Value2
1 Marco 20090504 16:01:01.582 0.0000000 -0.0000400
2 James 20090504 23:01:01.582 -0.0001400 0.0000000
3 Louise 20090505 00:00:00.833 -0.0001100 -0.0001400
4 Martin 20090505 01:01:01.582 -0.0000400 -0.0001100
5 Jamie 20090505 02:01:01.582 0.0001100 -0.0000400
6 Cecilie 20090505 03:01:01.582 0.0000500 0.0001100
7 Ben 20090505 15:01:01.582 0.0000000 0.0000500
8 Amanda 20090505 16:01:01.582 -0.0000800 0.0000000
9 Ida 20090505 23:01:01.582 0.0000000 -0.0000800

The timestamp column is a varchar.

I have now tried for a week to figure this out myself, and I think it is quite straighforward, but obviously not to me :-)

What I want is to calculate some stuff everytime the hour changes to 16:00:00. In this concrete example I would for instance want to calculate all the changes in column "Value1" between the 16:00:00 times. In the concrete example that would correspond to returning row 7 with two extra columns "Sum1" = sum of "Value1" from row 1 to row 7 and "Sum2" = sum of "Value2" from row 1 to row 7.

I would appreciate some help on this so much that you can't imagine!

Thanks,
Marco

Options: ReplyQuote




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.