0
0
SQLquery~10 mins

NTILE for distribution in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A3
B5
C2
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number other than 4 when 4 groups are needed.
Forgetting to specify the number inside NTILE.
2fill in blank
medium

Complete 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'
A4
B2
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using NTILE with a number other than 4 for quartiles.
Ordering by wrong column.
3fill in blank
hard

Fix 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'
A4
B0
C3
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative numbers in NTILE.
Using a number different from 3 when 3 groups are needed.
4fill in blank
hard

Fill 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'
A5
BASC
CDESC
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using ASC instead of DESC for descending order.
Using wrong number of groups.
5fill in blank
hard

Fill 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'
A4
BDESC
C=
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator in WHERE clause.
Using ascending order when descending is needed.