Write conditional aggregation SQL queries
Company: PayPal
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: Medium
Interview Round: Onsite
##### Question
Write an SQL query to compute the total amount for rows satisfying a condition, comparing approaches that use SUM(CASE WHEN … THEN … END) versus a simple SUM with a WHERE filter. Rewrite the query from Question 1 using CASE WHEN for conditional aggregation. Given a grouped query, place an aggregation filter in the HAVING clause; explain whether the syntax works in MySQL and why.
Quick Answer: This question evaluates proficiency with conditional aggregation in SQL, including the use of SUM(CASE WHEN ...) versus filtering with WHERE and the implications of placing aggregation filters in HAVING for grouped queries, within the Data Manipulation (SQL/Python) domain.