0
0
SQLquery~5 mins

NTILE for distribution in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the NTILE function do in SQL?
NTILE divides rows in a result set into a specified number of groups, called tiles, and assigns a tile number to each row to show which group it belongs to.
Click to reveal answer
intermediate
How does NTILE handle rows when they can't be evenly divided into tiles?
NTILE distributes the extra rows one by one to the first tiles until all rows are assigned, so some tiles may have one more row than others.
Click to reveal answer
beginner
Write a simple SQL query using NTILE to split 10 rows into 3 groups ordered by a column named 'score'.
SELECT score, NTILE(3) OVER (ORDER BY score) AS tile FROM your_table;
Click to reveal answer
intermediate
Can NTILE be used without an ORDER BY clause inside the OVER() function? Why or why not?
No, NTILE requires an ORDER BY clause inside OVER() to define how rows are sorted before dividing into tiles. Without ordering, the distribution would be unpredictable.
Click to reveal answer
beginner
What is a practical use case for NTILE in real life?
NTILE can be used to divide students into performance groups (like top 25%, middle 50%, bottom 25%) based on their test scores for targeted support.
Click to reveal answer
What does NTILE(4) do when applied to 10 rows?
ADivides rows into 10 groups, one row each
BDivides rows into 4 groups, each with exactly 2 rows
CDivides rows into 4 groups, some groups having 3 rows and some 2 rows
DDivides rows into 4 groups, each with exactly 4 rows
Which clause is mandatory inside the OVER() clause when using NTILE?
APARTITION BY
BORDER BY
CGROUP BY
DWHERE
If you want to split data into 5 equal groups, which NTILE argument should you use?
ANTILE(5)
BNTILE(10)
CNTILE(1)
DNTILE(0)
What happens if the number of rows is less than the NTILE number?
AAll rows go to the first tile
BAn error occurs
CRows are duplicated to fill tiles
DSome tiles will be empty
Which SQL clause can be combined with NTILE to restart numbering for each group?
APARTITION BY
BWHERE
CGROUP BY
DHAVING
Explain how NTILE distributes rows into groups when the total number of rows is not divisible evenly by the number of tiles.
Think about how leftover rows are assigned.
You got /3 concepts.
    Describe a real-world scenario where using NTILE would help organize data effectively.
    Consider grouping people or items based on scores or values.
    You got /3 concepts.