MySQL Forums
Forum List  »  General

Sum values only if successor is lower
Posted by: Björn von Heesen
Date: April 17, 2015 08:05AM

Hello,

is it possible to subtract a difference of values only if the successor is lower?

It's hard to explain for me, therefore here an example:

Let's take this given values: 100, 120, 140, 110, 130, 105, 110, 80 (quantity can vary).

The values are stock values and I want to calculate the sold items.

Result should be:

(140 - 110) + (130 - 105) + (110 - 80) = 30 + 25 + 30 = 85 (sold units)

Kind regards,
Bjoern

Options: ReplyQuote


Subject
Written By
Posted
Sum values only if successor is lower
April 17, 2015 08:05AM


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.