I need your help.
I have below sample data and want to compare Cell F (column Snap_Id) with previous row value.
e.g. row_num 2 should compare with row_num 1 and if it is matching it should say "No" and if it is not matching like row_num 3 compare with row_num 2 then it should say "Yes".
Id | CaseId | User | CaseStatus | DateCreated | Snap_Id | row_num |
---|---|---|---|---|---|---|
11 | 100 | Raj | 3 | 2023-04-27 | null | 1 |
22 | 100 | Mike | 3 | 2023-06-22 | null | 2 |
33 | 100 | RJ | 5 | 2023-06-30 | 33 | 3 |
44 | 100 | Mike | 3 | 2023-07-04 | null | 4 |
55 | 100 | RJ | 5 | 2023-07-04 | 55 | 5 |
55 | 100 | RJ | 5 | 2023-07-05 | 55 | 6 |
Can you please help me to write SQL statement to achieve it. I tried self join but then it is returning me 12 records with incorrect data.
The final output I am expecting is as below,
Id | CaseId | User | CaseStatus | DateCreated | Snap_Id | row_num | Result |
---|---|---|---|---|---|---|---|
11 | 100 | Raj | 3 | 2023-04-27 | null | 1 | No |
22 | 100 | Mike | 3 | 2023-06-22 | null | 2 | Yes |
33 | 100 | RJ | 5 | 2023-06-30 | 33 | 3 | Yes |
44 | 100 | Mike | 3 | 2023-07-04 | null | 4 | Yes |
55 | 100 | RJ | 5 | 2023-07-04 | 55 | 5 | Yes |
55 | 100 | RJ | 5 | 2023-07-05 | 55 | 6 | No |
Hope you can help me with this.
Thanks in advance.
Regards,
Abhishek
You need to sign in to view this answers