Complete the code to divide rows into 4 groups using NTILE.
SELECT name, salary, NTILE([1]) OVER (ORDER BY salary) AS quartile FROM employees;The NTILE function divides rows into the specified number of groups. Here, 4 groups (quartiles) are needed.
Complete the code to assign 3 groups to rows ordered by score.
SELECT player, score, NTILE([1]) OVER (ORDER BY score DESC) AS group_num FROM leaderboard;NTILE(3) divides the rows into 3 groups ordered by score descending.
Complete the code to divide rows into 5 groups.
SELECT id, value, NTILE([1]) OVER (ORDER BY value) AS group_id FROM data;The NTILE function needs the number of groups as argument. Here, 5 groups are required.
Fill both blanks to divide employees into 3 groups ordered by age.
SELECT name, age, NTILE([1]) OVER (ORDER BY [2]) AS age_group FROM employees;
NTILE(3) divides into 3 groups. Ordering by age sorts rows by age for grouping.
Fill all three blanks to create quartiles of sales and show group and sales.
SELECT salesperson, sales, NTILE([1]) OVER (ORDER BY [2] [3]) AS sales_quartile FROM sales_data;
NTILE(4) creates 4 groups (quartiles). Ordering by sales ascending groups from lowest to highest sales.