Prime Batch Warehouse Capacity
Beginner Mode
Objective
Write a SQL query to determine the maximum number of prime and non-prime batches that can be stored in a 500,000 square-foot warehouse. Prime batches must be fully stocked first, and any remaining space should be used for non-prime batches.
Table Schema:
- inventory
| Column | Type | Description |
|---|---|---|
| item_id | INTEGER | Unique identifier for the item |
| item_type | VARCHAR | Type of item ('prime_eligible' or 'not_prime') |
| square_footage | INTEGER | Space required per batch of this item |
| item_count | INTEGER | Number of batches available for this item |
Task Requirements:
- Calculate the total number of prime batches and their total square footage
- All prime batches are stocked first (assume they fit within the warehouse)
- Use the remaining space to calculate the maximum number of non-prime batches that can be stored
- Output prime results before non-prime results
Output columns: item_type, max_batch_count
Examples
Example 1:
Output:
Input:
| inventory | |||
|---|---|---|---|
| item_count | item_id | item_type | square_footage |
| 200 | 1 | prime_eligible | 500 |
| 150 | 2 | prime_eligible | 500 |
| 300 | 3 | not_prime | 700 |
| 250 | 4 | not_prime | 700 |
| item_type | max_batch_count |
|---|---|
| prime_eligible | 350 |
| not_prime | 464 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Amazon