This question evaluates a candidate's ability to implement conditional aggregation in SQL using CASE WHEN, assessing practical query-writing skills and understanding of conditional expressions for grouped counts and conditional sums.
Write a query that produces conditional aggregates using CASE WHEN (e.g., counts of approved vs declined transactions per merchant and the sum of amounts flagged for review). Explain why CASE WHEN is the portable approach across SQL dialects compared with dialect-specific boolean-to-integer coercion (e.g., SUM(column = 'x')). Discuss readability and maintainability trade-offs.