Homedepot·Software Engineer·Technical Phone Screen
- A query joining sales, sale items, products, and promotions is returning far fewer rows than expected for mulch sales over the last 30 days. Why is it dropping rows, and what is the root cause?
- Walk through a step-by-step approach to debug which join or filter is causing unexpected row loss in a multi-table SQL query.
- Rewrite the buggy query so it correctly returns total mulch units, total mulch revenue, and promo mulch units for each day in the last 30 days, including days with no active promotion.
“The bug is that the WHERE clause filters on p.discount_pct > 0, which kills the LEFT JOIN.”