0
0
PostgreSQLquery~10 mins

NTILE for distribution in PostgreSQL - 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.

PostgreSQL
SELECT name, salary, NTILE([1]) OVER (ORDER BY salary) AS quartile FROM employees;
Drag options to blanks, or click blank then click option'
A4
B3
C5
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 or 5 instead of 4 for quartiles.
Forgetting to order rows inside OVER clause.
2fill in blank
medium

Complete the code to assign 3 groups to rows ordered by score.

PostgreSQL
SELECT player, score, NTILE([1]) OVER (ORDER BY score DESC) AS group_num FROM leaderboard;
Drag options to blanks, or click blank then click option'
A3
B2
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of groups.
Not ordering scores descending to get top scores first.
3fill in blank
hard

Complete the code to divide rows into 5 groups.

PostgreSQL
SELECT id, value, NTILE([1]) OVER (ORDER BY value) AS group_id FROM data;
Drag options to blanks, or click blank then click option'
A4
B6
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Missing ORDER BY inside OVER clause.
Using wrong number of groups.
4fill in blank
hard

Fill both blanks to divide employees into 3 groups ordered by age.

PostgreSQL
SELECT name, age, NTILE([1]) OVER (ORDER BY [2]) AS age_group FROM employees;
Drag options to blanks, or click blank then click option'
A3
Bage
Csalary
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column in ORDER BY.
Using wrong number of groups.
5fill in blank
hard

Fill all three blanks to create quartiles of sales and show group and sales.

PostgreSQL
SELECT salesperson, sales, NTILE([1]) OVER (ORDER BY [2] [3]) AS sales_quartile FROM sales_data;
Drag options to blanks, or click blank then click option'
A4
Bsales
CDESC
DASC
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of groups.
Ordering by wrong column or wrong direction.