Bird
0
0

Given a table employees with salaries: 3000, 4000, 5000, 6000, 7000, what is the NTILE(3) bucket for salary 6000?

medium📝 query result Q4 of 15
PostgreSQL - Window Functions in PostgreSQL
Given a table employees with salaries: 3000, 4000, 5000, 6000, 7000, what is the NTILE(3) bucket for salary 6000?

Query:
SELECT salary, NTILE(3) OVER (ORDER BY salary) AS bucket FROM employees;
A2
B1
C3
D4
Step-by-Step Solution
Solution:
  1. Step 1: Order salaries and divide into 3 buckets

    5 rows divided into 3 buckets: first 2 rows in bucket 1, next 2 in bucket 2, last 1 in bucket 3.
  2. Step 2: Locate salary 6000

    6000 is the 4th salary in order, so it falls in bucket 2.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    NTILE assigns buckets based on ordered row position [OK]
Quick Trick: NTILE buckets depend on row order and count [OK]
Common Mistakes:
  • Assuming equal bucket sizes without leftovers
  • Miscounting row positions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes