sql >> Base de Datos >  >> RDS >> Sqlserver

¿Cómo mostrar solo filas pares o impares en el servidor sql 2008?

Consulte ROW_NUMBER()

SELECT t.First, t.Last
FROM (
    SELECT *, Row_Number() OVER(ORDER BY First, Last) AS RowNumber 
            --Row_Number() starts with 1
    FROM Table1
) t
WHERE t.RowNumber % 2 = 0 --Even
--WHERE t.RowNumber % 2 = 1 --Odd