Junior
Window Functions
SQL & Databases
Write a query to find odd / even rows using ROW_NUMBER.
Short answer: Assign ROW_NUMBER() then filter rn % 2 = 1 for odd rows. Useful in puzzles; rare in production.
Sample solution
T-SQL
SELECT *
FROM (
SELECT *, ROW_NUMBER() OVER (ORDER BY EmpId) AS rn
FROM Employees
) t
WHERE rn % 2 = 1;
Clarify ordering — “odd rows” is meaningless without ORDER BY.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png