Shown Previous row value into next row value such condition

Issue

This Content is from Stack Overflow. Question asked by snehassis

My table is below:

TranType | Date      | ItemID| Rate |
---------|-----------|-------| -----|
PUR      |2021-04-01 | 1     |  16  |
SAL      |2021-04-05 | 1     |   0  |
SAL      |2021-04-06 | 1     |   0  |
SAL      |2021-04-16 | 1     |   0  |
SAL      |2021-04-19 | 1     |   0  |
PUR      |2021-04-23 | 1     |  18  |
SAL      |2021-04-26 | 1     |   0  |
SAL      |2021-04-27 | 1     |   0  |
PUR      |2021-04-28 | 1     |  20  |
SAL      |2021-05-07 | 1     |  0   |

I want to out put my result as shown below:

TranType | Date      | ItemID| Rate |
---------|-----------|-------| -----|
PUR      |2021-04-01 | 1     |  16  |
SAL      |2021-04-05 | 1     |  16  |
SAL      |2021-04-06 | 1     |  16  |
SAL      |2021-04-16 | 1     |  16  |
SAL      |2021-04-19 | 1     |  16  |
PUR      |2021-04-23 | 1     |  18  |
SAL      |2021-04-26 | 1     |  18  |
SAL      |2021-04-27 | 1     |  18  |
PUR      |2021-04-28 | 1     |  20  |
SAL      |2021-05-07 | 1     |  20  |

How can I solve above problem in any SQL database version.
Please help me.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?