PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Reinforce Labs

Write SQL to compute current product stock

Last updated: Mar 29, 2026

Quick Overview

This question evaluates SQL competence in aggregations and relational joins, including handling baselines, nullable data, temporal filtering, and accurate net inventory calculation across multiple event tables.

  • medium
  • Reinforce Labs
  • Software Engineering Fundamentals
  • Software Engineer

Write SQL to compute current product stock

Company: Reinforce Labs

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Take-home Project

You need to generate a report showing the **current on-hand stock** for each product. Stock changes over time due to: - **Incoming shipments** (increase stock) - **Customer orders** (decrease stock) - **Customer returns** (increase stock) Assume the following tables: - `products(product_id, name)` - `inventory_baseline(product_id, baseline_qty)` — starting on-hand quantity (may be missing for some products) - `incoming_shipments(shipment_id, product_id, qty, received_at)` - `order_items(order_id, product_id, qty, ordered_at)` - `returns(return_id, product_id, qty, returned_at)` **Task:** Write a SQL query that returns one row per product: - `product_id` - `name` - `current_stock` Where: \[ \text{current_stock} = \text{baseline_qty} + \sum(\text{incoming qty}) + \sum(\text{return qty}) - \sum(\text{ordered qty}) \] Requirements: - Include products even if they have no shipments/orders/returns (treat missing quantities as 0). - Avoid double-counting due to join multiplication. - (Optional) If helpful, also show how you would filter to “as of” a given timestamp.

Quick Answer: This question evaluates SQL competence in aggregations and relational joins, including handling baselines, nullable data, temporal filtering, and accurate net inventory calculation across multiple event tables.

Reinforce Labs logo
Reinforce Labs
Jan 8, 2026, 12:00 AM
Software Engineer
Take-home Project
Software Engineering Fundamentals
1
0
Loading...

You need to generate a report showing the current on-hand stock for each product. Stock changes over time due to:

  • Incoming shipments (increase stock)
  • Customer orders (decrease stock)
  • Customer returns (increase stock)

Assume the following tables:

  • products(product_id, name)
  • inventory_baseline(product_id, baseline_qty) — starting on-hand quantity (may be missing for some products)
  • incoming_shipments(shipment_id, product_id, qty, received_at)
  • order_items(order_id, product_id, qty, ordered_at)
  • returns(return_id, product_id, qty, returned_at)

Task: Write a SQL query that returns one row per product:

  • product_id
  • name
  • current_stock

Where:

\text{current_stock} = \text{baseline_qty} + \sum(\text{incoming qty}) + \sum(\text{return qty}) - \sum(\text{ordered qty})

Requirements:

  • Include products even if they have no shipments/orders/returns (treat missing quantities as 0).
  • Avoid double-counting due to join multiplication.
  • (Optional) If helpful, also show how you would filter to “as of” a given timestamp.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Reinforce Labs•More Software Engineer•Reinforce Labs Software Engineer•Reinforce Labs Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals
PracHub

Master your tech interviews with 8,000+ 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.