Bird
0
0

Which of the following is the correct syntax to assign quartiles using NTILE in PostgreSQL?

easy📝 Syntax Q12 of 15
PostgreSQL - Window Functions in PostgreSQL
Which of the following is the correct syntax to assign quartiles using NTILE in PostgreSQL?
ASELECT column, NTILE(4) PARTITION BY column FROM table;
BSELECT column, NTILE OVER (4 ORDER BY column) AS quartile FROM table;
CSELECT column, NTILE(4) AS quartile FROM table ORDER BY column;
DSELECT column, NTILE(4) OVER (ORDER BY column) AS quartile FROM table;
Step-by-Step Solution
Solution:
  1. Step 1: Recall NTILE syntax

    The correct syntax is NTILE(n) OVER (ORDER BY column) to assign groups.
  2. Step 2: Check each option

    SELECT column, NTILE(4) OVER (ORDER BY column) AS quartile FROM table; uses correct syntax with NTILE(4) OVER (ORDER BY column). Others misuse OVER clause or omit it.
  3. Final Answer:

    SELECT column, NTILE(4) OVER (ORDER BY column) AS quartile FROM table; -> Option D
  4. Quick Check:

    NTILE needs OVER with ORDER BY [OK]
Quick Trick: NTILE requires OVER and ORDER BY clauses [OK]
Common Mistakes:
  • Omitting OVER clause
  • Placing number inside OVER incorrectly
  • Using PARTITION BY without ORDER BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes