Complete the code to divide rows into 4 groups using NTILE.
SELECT employee_id, salary, NTILE([1]) OVER (ORDER BY salary DESC) AS salary_group FROM employees;The NTILE function divides rows into the specified number of groups. Here, 4 groups are requested.
Complete the code to assign quartiles based on sales amount.
SELECT customer_id, sales_amount, NTILE([1]) OVER (ORDER BY sales_amount) AS quartile FROM sales;Quartiles divide data into 4 equal parts, so NTILE(4) is used.
Fix the error in the NTILE function to split data into 3 groups.
SELECT product_id, price, NTILE([1]) OVER (ORDER BY price DESC) AS price_group FROM products;NTILE requires a positive integer greater than zero. 3 groups means NTILE(3).
Fill both blanks to create 5 groups ordered by score descending.
SELECT student_id, score, NTILE([1]) OVER (ORDER BY score [2]) AS score_group FROM students;
NTILE(5) creates 5 groups. Ordering by score descending uses DESC.
Fill all three blanks to assign NTILE groups and filter for group 1 only.
WITH ranked AS (SELECT order_id, amount, NTILE([1]) OVER (ORDER BY amount [2]) AS group_num FROM orders) SELECT * FROM ranked WHERE group_num [3] 1;
NTILE(4) divides into 4 groups, ordered descending by amount. Filtering for group_num = 1 selects the first group.
