Bird
0
0

Which of the following is the correct way to write a GROUPING SETS clause in PostgreSQL to group by department and region separately?

easy📝 Syntax Q3 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Which of the following is the correct way to write a GROUPING SETS clause in PostgreSQL to group by department and region separately?
AGROUP BY GROUPING SETS (department, region)
BGROUP BY GROUPING SETS ((department), (region))
CGROUP BY GROUPING SETS [department, region]
DGROUP BY GROUPING SETS {department, region}
Step-by-Step Solution
Solution:
  1. Step 1: Understand GROUPING SETS syntax

    GROUPING SETS requires parentheses around each grouping set.
  2. Step 2: Analyze options

    GROUP BY GROUPING SETS ((department), (region)) correctly uses double parentheses for each grouping set. Options B, C, and D use incorrect syntax.
  3. Final Answer:

    GROUP BY GROUPING SETS ((department), (region)) -> Option B
  4. Quick Check:

    Correct syntax uses double parentheses for each grouping set [OK]
Quick Trick: Use double parentheses for each grouping set [OK]
Common Mistakes:
  • Omitting parentheses around individual grouping sets
  • Using square or curly brackets instead of parentheses
  • Listing columns without parentheses inside GROUPING SETS

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes