๐ง SQL Interview Question (Moderate & Analytical)
๐
events(user_id, event_name, event_date)
-- event_name values: 'Visited', 'Added_to_Cart', 'Purchased'
โ Ques :
๐ Find users who added a product to cart but never completed the purchase.
๐งฉ How Interviewers Expect You to Think
โข Understand funnel stage logic
โข Apply conditional aggregation correctly
โข Ensure absence of a specific event
โข Avoid double counting users
๐ก SQL Solution
SELECT
user_id
FROM events
GROUP BY user_id
HAVING
SUM(CASE WHEN event_name = 'Added_to_Cart' THEN 1 ELSE 0 END) > 0
AND SUM(CASE WHEN event_name = 'Purchased' THEN 1 ELSE 0 END) = 0;
๐ฅ Why This Question Is Powerful
โข Tests real business thinking (conversion funnel analysis)
โข Checks ability to detect missing conditions
โข Common in product & e-commerce analytics interviews
โข Evaluates aggregation + logical filtering skills together
โค๏ธ React if you want more real interview-level SQL questions
Post #2080
1.72K
- โค 7