Recall & Review
beginner
What does the NTILE function do in SQL?
NTILE divides rows in a result set into a specified number of groups, assigning a group number to each row to show its distribution.
Click to reveal answer
intermediate
How does NTILE assign group numbers when the rows don't divide evenly?
NTILE assigns extra rows to the first groups so that groups at the start have one more row than later groups.
Click to reveal answer
beginner
Write a simple NTILE query to split 10 rows into 3 groups ordered by salary.
SELECT employee_id, salary, NTILE(3) OVER (ORDER BY salary) AS group_number FROM employees;
Click to reveal answer
beginner
Why is the ORDER BY clause important in the NTILE function?
ORDER BY defines how rows are sorted before being divided into groups, affecting which rows fall into each group.
Click to reveal answer
intermediate
Can NTILE be used without an ORDER BY clause? What happens?
No, NTILE requires ORDER BY to define row order; without it, the function will cause an error.
Click to reveal answer
What does NTILE(4) do to a result set?
✗ Incorrect
NTILE(4) splits the rows into 4 groups and assigns each row a group number from 1 to 4.
If you have 10 rows and use NTILE(3), how many rows will the first group have?
✗ Incorrect
Since 10 divided by 3 is 3 with remainder 1, the first group gets 4 rows, others get 3.
Which clause must be used with NTILE to define row order?
✗ Incorrect
NTILE requires ORDER BY to sort rows before dividing them into groups.
What type of SQL function is NTILE?
✗ Incorrect
NTILE is a window function that works over a set of rows.
What happens if you use NTILE(1) on a result set?
✗ Incorrect
NTILE(1) puts all rows into a single group numbered 1.
Explain how NTILE distributes rows into groups and how it handles uneven division.
Think about how you would split a class into teams when the number of students isn't divisible evenly.
You got /3 concepts.
Describe a real-life scenario where NTILE could be useful in analyzing data.
Consider how businesses or schools categorize people based on rankings or scores.
You got /3 concepts.