Bird
0
0

Which of the following is the correct syntax to use CUBE in a PostgreSQL query?

easy📝 Syntax Q12 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Which of the following is the correct syntax to use CUBE in a PostgreSQL query?
ASELECT col1, col2, SUM(sales) FROM table CUBE BY (col1, col2);
BSELECT col1, col2, SUM(sales) FROM table GROUP BY CUBE col1, col2;
CSELECT col1, col2, SUM(sales) FROM table GROUP BY ROLLUP(col1, col2);
DSELECT col1, col2, SUM(sales) FROM table GROUP BY CUBE(col1, col2);
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct GROUP BY syntax with CUBE

    The correct syntax is GROUP BY CUBE(col1, col2) with parentheses around columns.
  2. Step 2: Identify incorrect options

    SELECT col1, col2, SUM(sales) FROM table CUBE BY (col1, col2); uses invalid 'CUBE BY', C uses ROLLUP, D misses parentheses.
  3. Final Answer:

    SELECT col1, col2, SUM(sales) FROM table GROUP BY CUBE(col1, col2); -> Option D
  4. Quick Check:

    GROUP BY CUBE(columns) syntax [OK]
Quick Trick: Use GROUP BY CUBE(col1, col2) with parentheses [OK]
Common Mistakes:
  • Omitting parentheses in CUBE
  • Using 'CUBE BY' instead of 'GROUP BY CUBE'
  • Confusing ROLLUP and CUBE syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes