Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to divide rows into 4 groups using NTILE.
SQL
SELECT employee_id, salary, NTILE([1]) OVER (ORDER BY salary DESC) AS salary_group FROM employees; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number other than 4 when 4 groups are needed.
Forgetting to specify the number inside NTILE.
✗ Incorrect
The NTILE function divides rows into the specified number of groups. Here, 4 groups are requested.
2fill in blank
mediumComplete the code to assign quartiles based on sales amount.
SQL
SELECT customer_id, sales_amount, NTILE([1]) OVER (ORDER BY sales_amount) AS quartile FROM sales; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NTILE with a number other than 4 for quartiles.
Ordering by wrong column.
✗ Incorrect
Quartiles divide data into 4 equal parts, so NTILE(4) is used.
3fill in blank
hardFix the error in the NTILE function to split data into 3 groups.
SQL
SELECT product_id, price, NTILE([1]) OVER (ORDER BY price DESC) AS price_group FROM products; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative numbers in NTILE.
Using a number different from 3 when 3 groups are needed.
✗ Incorrect
NTILE requires a positive integer greater than zero. 3 groups means NTILE(3).
4fill in blank
hardFill both blanks to create 5 groups ordered by score descending.
SQL
SELECT student_id, score, NTILE([1]) OVER (ORDER BY score [2]) AS score_group FROM students;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ASC instead of DESC for descending order.
Using wrong number of groups.
✗ Incorrect
NTILE(5) creates 5 groups. Ordering by score descending uses DESC.
5fill in blank
hardFill all three blanks to assign NTILE groups and filter for group 1 only.
SQL
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;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator in WHERE clause.
Using ascending order when descending is needed.
✗ Incorrect
NTILE(4) divides into 4 groups, ordered descending by amount. Filtering for group_num = 1 selects the first group.