-2

I have a table. I want to compare each row with next row till all rows. If matched I need to display only mismatch values.

TABLE_A

  1. A      B      C
    
  2. A      B      D
    
  3. E      A      E
    
  4. A      C      E
    

.. .. .. nth

Output should be

  1. A         B         C
    
  2. NULL      NULL      D
    
  3. E         A         E
    
  4. A         C         NULL
    

.. .. .. nth

Md Umar
  • 35
  • 6
  • 2
    Have you had a look at `LAG`/`LEAD`? – Thom A Aug 01 '22 at 07:22
  • 1
    Do you have a column that you can actually order by? Your question implies you don't, however, is the number bullet point actually part of the data? – Thom A Aug 01 '22 at 08:47

1 Answers1

-1

Take a look at the SQL Lag function. This website explains how it works. Example 1 is very clear https://www.sqlshack.com/sql-lag-function-overview-and-examples/

SELECT *, 
       Lag(JoiningDate, 1) OVER(.
       ORDER BY JoiningDate ASC) AS EndDate
FROM @Employee;

makes:

enter image description here

Thom A
  • 88,727
  • 11
  • 45
  • 75
Joost00719
  • 716
  • 1
  • 5
  • 20