How to Find the Even and Odd records from a table | SQL interview questions #coding #developer

preview_player
Показать описание
In this video, we're going to learn a cool SQL trick: how to select rows with even row numbers. This is a really useful skill to have, especially if you're working with large datasets.

We'll start by using the ROW_NUMBER function to assign a unique sequential number to each row in a result set. Then, we'll use the MOD function to check if the row number is divisible by 2. If it is, then the row number is even and we'll select the row.

This is a really simple query, but it can be very powerful. You can use it to select specific rows from a dataset or to split a dataset into two groups.

So, let's get started!

-------------------------------------------------------------------------
►►►Social Media – Where I sort of Live
-------------------------------------------------------------------------
►►►Books I refer to
-------------------------------------------------------------------------
►►►Camera Gears
► Video Gears That We Use For Creating Our YouTube Video

► Work From Home Essential Tech That We Use Daily

AFFILIATE DISCLOSURE:
#RebellionRider
Рекомендации по теме
Комментарии
Автор

SELECT name, salary
FROM (
SELECT name, salary, ROW_NUMBER() OVER (ORDER BY salary) AS row_number
FROM employees
) AS subquery
WHERE MOD(row_number, 2) = 0;

nibibinu
Автор

Solutions to even number


SELECT * FROM
(
SELECT

name, salary,

ROW_NUMBER() OVER (

ORDER BY salary) AS row_number

FROM employees

) AS subquery

WHERE row_number % 2 = 0;

nibibinu
visit shbcf.ru