
Price after discount
mediumPrice after discount
Walmart SQL Interview Question
Walmart's checkout team needs the price a customer actually pays for each product. A discount of 10 means 10% off, and a product with no discount recorded sells at its full price.
List the product_name, the original price, and the price after any discount as final_price, rounded to 2 decimal places.
Asked of
- Data Analyst
- Business Analyst
- BI Analyst
- Product Analyst
- Analytics Engineer
productsTable15 rows
| Column Name | Type |
|---|---|
| product_id | BIGINT |
| product_name | VARCHAR |
| category | VARCHAR |
| brand | VARCHAR |
| price | DOUBLE |
| discount_pct | BIGINT |
| stock_quantity | BIGINT |
| launch_date | DATE |
| is_active | BOOLEAN |
productsExample Input
| product_id | product_name | category | brand | price | discount_pct | stock_quantity | launch_date | is_active |
|---|---|---|---|---|---|---|---|---|
| 1 | Wireless Mouse | Electronics | Logitech | 24.99 | 10 | 150 | 2023-02-14 | true |
| 2 | Mechanical Keyboard Pro | Electronics | Keychron | 119 | NULL | 40 | 2023-05-01 | true |
| 3 | Noise Canceling Headphones | Electronics | Sony | 299.99 | 15 | 0 | 2022-11-20 | true |
| 4 | Standing Desk | Furniture | Flexispot | 349 | NULL | 12 | 2023-08-09 | true |
| 5 | Ergonomic Chair Pro | Furniture | Steelcase | 1299 | 5 | 5 | 2021-06-30 | true |
| 6 | Desk Lamp | Furniture | NULL | 39.5 | NULL | 80 | 2024-01-15 | true |
| 7 | USB-C Hub | Electronics | Anker | 45 | 20 | 200 | 2023-03-22 | true |
| 8 | Notebook Set | Stationery | Moleskine | 18 | NULL | 0 | 2022-09-01 | false |
Example Output
| product_name | price | final_price |
|---|---|---|
| Desk Lamp | 39.5 | 39.5 |
| Ergonomic Chair Pro | 1299 | 1234.05 |
| Mechanical Keyboard Pro | 119 | 119 |
| Noise Canceling Headphones | 299.99 | 254.99 |
| Notebook Set | 18 | 18 |
| Standing Desk | 349 | 349 |
| USB-C Hub | 45 | 36 |
| Wireless Mouse | 24.99 | 22.49 |
Explanation
The Wireless Mouse costs 24.99 and has 10% off, so its final price is 22.49. The Mechanical Keyboard Pro has no discount recorded, so it still sells for its full price of 119.
The example above is a small slice of the data. Your query runs against the full tables.
Company
Walmart
Difficulty
medium
Topic
null handling
Your query
Starting the SQL engine...