Bird
0
0

Which of the following is the correct way to write a GROUP BY clause using ROLLUP for columns department and month in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Which of the following is the correct way to write a GROUP BY clause using ROLLUP for columns department and month in PostgreSQL?
AGROUP BY CUBE(department, month)
BGROUP BY ROLLUP department, month
CGROUP BY ROLLUP(department, month)
DGROUP BY department, month WITH ROLLUP
Step-by-Step Solution
Solution:
  1. Step 1: Recall ROLLUP syntax

    ROLLUP is used as a function with parentheses around the columns: ROLLUP(col1, col2).
  2. Step 2: Evaluate options

    GROUP BY ROLLUP(department, month) uses correct syntax. GROUP BY ROLLUP department, month misses parentheses. GROUP BY CUBE(department, month) uses CUBE instead of ROLLUP. GROUP BY department, month WITH ROLLUP is invalid syntax in PostgreSQL.
  3. Final Answer:

    GROUP BY ROLLUP(department, month) -> Option C
  4. Quick Check:

    ROLLUP requires parentheses around columns [OK]
Quick Trick: ROLLUP syntax requires parentheses around columns [OK]
Common Mistakes:
  • Omitting parentheses in ROLLUP
  • Confusing ROLLUP with CUBE syntax
  • Using non-PostgreSQL syntax like WITH ROLLUP

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes