Bird
0
0

You want to divide 7 employees into 3 salary groups using NTILE, but the salaries are:

hard📝 Application Q15 of 15
PostgreSQL - Window Functions in PostgreSQL
You want to divide 7 employees into 3 salary groups using NTILE, but the salaries are:
5000, 7000, 7000, 9000, 11000, 11000, 13000.
Which NTILE(3) group assignment is correct when ordered by salary?
A[{5000,1}, {7000,1}, {7000,1}, {9000,2}, {11000,2}, {11000,3}, {13000,3}]
B[{5000,1}, {7000,1}, {7000,2}, {9000,3}, {11000,3}, {11000,3}, {13000,3}]
C[{5000,1}, {7000,2}, {7000,2}, {9000,2}, {11000,3}, {11000,3}, {13000,3}]
D[{5000,1}, {7000,1}, {7000,2}, {9000,2}, {11000,3}, {11000,3}, {13000,3}]
Step-by-Step Solution
Solution:
  1. Step 1: Calculate group sizes for 7 rows and 3 groups

    7 rows divided into 3 groups: first group gets 3 rows, next two get 2 rows each.
  2. Step 2: Assign groups by ordered salary

    Order: 5000(1), 7000(1), 7000(2), 9000(3), 11000(3), 11000(3), 13000(3).
  3. Final Answer:

    [{5000,1}, {7000,1}, {7000,2}, {9000,3}, {11000,3}, {11000,3}, {13000,3}] -> Option B
  4. Quick Check:

    7 rows split into 3 groups: 3,2,2 [OK]
Quick Trick: Extra rows go to earlier groups; order matters [OK]
Common Mistakes:
  • Ignoring duplicate salaries affecting group boundaries
  • Assigning equal rows per group ignoring total rows
  • Misplacing group numbers for duplicates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes