PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches

Quick Overview

This question evaluates proficiency in SQL aggregation and filtering (GROUP BY and HAVING), join selection and performance, date-range filtering, handling zero denominators and numeric rounding, plus schema indexing for query efficiency.

  • Medium
  • Meta
  • Data Manipulation (SQL/Python)
  • Data Scientist

Write SQL with HAVING and efficient joins

Company: Meta

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: Medium

Interview Round: Technical Screen

You are given two tables. Schema - interactions(product_id INT, buyer_id INT, seller_id INT, interaction_date DATE, interaction_type VARCHAR, interaction_count INT) - products(product_id INT PRIMARY KEY, country VARCHAR, category VARCHAR) Sample data products product_id | country | category 1 | US | electronics 2 | US | apparel 3 | CA | electronics 4 | US | home interactions product_id | buyer_id | seller_id | interaction_date | interaction_type | interaction_count 1 | 101 | 201 | 2025-08-26 | view | 3 1 | 102 | 201 | 2025-08-27 | validate | 2 1 | 101 | 201 | 2025-08-28 | click | 1 1 | 103 | 201 | 2025-08-29 | validate | 4 2 | 104 | 202 | 2025-08-30 | validate | 5 2 | 105 | 202 | 2025-08-31 | view | 2 2 | 106 | 202 | 2025-09-01 | validate | 1 4 | 107 | 204 | 2025-08-27 | view | 7 3 | 108 | 203 | 2025-08-26 | validate | 2 1 | 104 | 201 | 2025-08-30 | view | 1 Assume "today" is 2025-09-01. Answer the following with ANSI SQL and explain any assumptions: (a) Return the number of products whose distinct buyer count is > 3 and whose total interaction_count (summing across all rows and dates) is > 10. Be careful to count DISTINCT buyers per product across the full history, not per day. Use GROUP BY correctly and justify your use of HAVING vs WHERE for the thresholds. (b) Compute the percentage of 'validate' interactions for US products in the past 7 days (inclusive window 2025-08-26 through 2025-09-01): numerator = sum of interaction_count where interaction_type = 'validate'; denominator = sum of interaction_count across all interaction types; both restricted to US products and the 7-day window. Use an INNER JOIN to filter to US products and explain why INNER JOIN is preferable to LEFT JOIN here. Specify how you handle a zero denominator (return 0.0 vs NULL) and how you round. (c) Show the exact SQL for (a) and (b). Then list indexes you would add on each table to make these queries efficient, and explain why HAVING is required for post-aggregation filters while WHERE is not.

Quick Answer: This question evaluates proficiency in SQL aggregation and filtering (GROUP BY and HAVING), join selection and performance, date-range filtering, handling zero denominators and numeric rounding, plus schema indexing for query efficiency.

Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Compute ad impression conversion rates - Meta (medium)
  • Count unconnected posts and reactions - Meta (medium)
  • Count heavy callers in 7 days - Meta (medium)
  • Write SQL for call metrics - Meta (medium)
  • Write SQL for multi-account metrics - Meta (medium)