Query to compare record against previous SQL? [closed]

0

Hello, I need to compare the records of a column in a single table. It is worth mentioning that the records do not follow an order

Columna1 type int
123
1213
13313
12
12
1213
1213

Something like that should be the query:

select (case when Columna1 = Columna1(registro_siguiente) then '0' else '1' end) as Resultado from tablaDatos
    
asked by Huntzberger 05.01.2019 в 20:42
source

1 answer

0

You can use the LEAD function like this, sorting by the Id

SELECT 
    T.Id,
    CASE 
        WHEN T.Columna1 = LEAD(T.Columna1, 1, 0) OVER (ORDER BY T.Id) THEN '0'
        ELSE '1'
    END AS [Igual al Siguiente]
FROM DBO.MyTable AS T
    
answered by 07.01.2019 / 07:08
source