Bird
0
0

Why might using the FILTER clause be preferred over using a CASE statement inside an aggregate function for conditional aggregation?

hard📝 Conceptual Q10 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Why might using the FILTER clause be preferred over using a CASE statement inside an aggregate function for conditional aggregation?
AFILTER improves readability and separates condition from aggregation
BFILTER executes faster because it avoids scanning rows
CCASE statements cannot be used inside aggregate functions
DFILTER automatically indexes the filtered rows
Step-by-Step Solution
Solution:
  1. Step 1: Compare FILTER and CASE usage

    FILTER clause clearly separates the condition from the aggregate function, making queries easier to read and maintain.
  2. Step 2: Evaluate other options

    FILTER does not avoid scanning rows or create indexes. CASE can be used inside aggregates. Performance differences are usually minimal.
  3. Final Answer:

    FILTER improves readability and separates condition from aggregation -> Option A
  4. Quick Check:

    FILTER = clearer syntax for conditional aggregation [OK]
Quick Trick: FILTER clause makes conditional aggregates easier to read [OK]
Common Mistakes:
  • Assuming FILTER improves performance significantly
  • Believing CASE cannot be used inside aggregates
  • Thinking FILTER creates indexes automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes