๐ช Product Price Comparison Across Stores
Imagine you're building a price comparison feature for an e-commerce platform! You have a database table containing product prices across different stores, but the data is stored in a normalized format (each row represents one product-store combination).
Your task: Transform this data into a user-friendly format where each product shows its price in all stores side by side, making it easy for customers to compare prices at a glance.
๐ Database Schema
+-------------+---------+| Column Name | Type |+-------------+---------+| product_id | int || store | enum || price | int |+-------------+---------+Primary Key: (product_id, store)
Store values: 'store1', 'store2', 'store3'
Goal: Create a result table where each row represents a product, and columns show the price in each store (store1, store2, store3). If a product isn't available in a store, show null.
This is a classic pivot table operation - converting rows to columns for better data presentation!
Input & Output
Visualization
Time & Space Complexity
Single pass through all rows in the products table
Where k is the number of unique products (for GROUP BY operation)
Constraints
- 1 โค number of rows โค 104
- store is an ENUM of type ('store1', 'store2', 'store3')
- 1 โค product_id โค 106
- 1 โค price โค 106
- Primary key: (product_id, store) - no duplicate combinations