Bird
0
0

Find the problem in this query:

medium📝 Debug Q7 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Find the problem in this query:
SELECT STRING_AGG(name, ',') FROM employees GROUP BY department;
Assuming name and department columns exist.
AMissing alias for STRING_AGG result
BNo error, query is valid
CSTRING_AGG cannot be used with GROUP BY
DSeparator must be a space, not a comma
Step-by-Step Solution
Solution:
  1. Step 1: Understand STRING_AGG with GROUP BY

    STRING_AGG is often used with GROUP BY to aggregate strings per group.
  2. Step 2: Check query validity

    The query syntax is correct; alias is optional, separator ',' is valid.
  3. Final Answer:

    No error, query is valid -> Option B
  4. Quick Check:

    STRING_AGG works with GROUP BY [OK]
Quick Trick: STRING_AGG commonly used with GROUP BY [OK]
Common Mistakes:
  • Thinking alias is mandatory
  • Believing separator must be space

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes