I have a requirement to update column3 of the following table by cross-checking value2 with the next row value1
If equal, then value3 = value1 * value2 and if not value3 = value1
CREATE TABLE
INSERT INTO
(1, 2), (2,3), (3,4), (4,5),(6,7),(7,8),(8,9)
Table # tmpValue1 will look like:
id value1 value2 value3 (expected output)
1 1 2 1
2 2 3 4
3 3 4 9
4 4 5 16
5 6 7 6
6 7 8 49
7 8 9 64
Above, in value3, updated from 1 in the first, because 2 lines of Value2 is first compared with 2 values โโof 1 line in the second, so it will start updating from the second.
Note. The values โโof Value1 and Value2 are just a sample and real, it may be different.
Fever source
share