MySQL Forums
Forum List  »  MySQL Query Browser

Question on Adding a New Column in Table
Posted by: Yu Xing Tay
Date: December 10, 2011 04:46AM

Suppose i have a table like this:

Name Value

A 20
A 25
B 30
B 46
B 72

What is the query i need to input to generate another column with the rule:
(if the name of the current row = name of prev row, then return current value - prev value. if the name of current row is not equal to name of prev row, return 0)

So the result will be:

Name Value Results

A 20 0
A 25 5
B 30 0
B 46 16
B 72 26

Thx a lot!

Options: ReplyQuote


Subject
Written By
Posted
Question on Adding a New Column in Table
December 10, 2011 04:46AM


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.