Bird
0
0

Consider the query:

medium📝 query result Q5 of 15
PostgreSQL - Window Functions in PostgreSQL
Consider the query:
SELECT department, employee, salary, SUM(salary) OVER (PARTITION BY department) AS dept_total FROM employees;

What does the dept_total column show?
ATotal salary for each department repeated on every row of that department
BTotal salary for all employees in the table
CRunning total of salary ordered by employee name
DAverage salary per employee in each department
Step-by-Step Solution
Solution:
  1. Step 1: Understand SUM() OVER with PARTITION BY

    SUM() with PARTITION BY calculates sum per group; here, per department.
  2. Step 2: Recognize repeated value per row

    The sum is repeated on every row within the department, not a running total or average.
  3. Final Answer:

    Total salary for each department repeated on every row of that department -> Option A
  4. Quick Check:

    SUM() OVER PARTITION BY = group total repeated [OK]
Quick Trick: SUM() OVER PARTITION BY repeats group total on each row [OK]
Common Mistakes:
  • Thinking it sums entire table ignoring partition
  • Confusing with running total or average
  • Expecting different values per row in same partition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes