Price after discount

null handling

Price 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 NameType
product_idBIGINT
product_nameVARCHAR
categoryVARCHAR
brandVARCHAR
priceDOUBLE
discount_pctBIGINT
stock_quantityBIGINT
launch_dateDATE
is_activeBOOLEAN

productsExample Input

product_idproduct_namecategorybrandpricediscount_pctstock_quantitylaunch_dateis_active
1Wireless MouseElectronicsLogitech24.99101502023-02-14true
2Mechanical Keyboard ProElectronicsKeychron119NULL402023-05-01true
3Noise Canceling HeadphonesElectronicsSony299.991502022-11-20true
4Standing DeskFurnitureFlexispot349NULL122023-08-09true
5Ergonomic Chair ProFurnitureSteelcase1299552021-06-30true
6Desk LampFurnitureNULL39.5NULL802024-01-15true
7USB-C HubElectronicsAnker45202002023-03-22true
8Notebook SetStationeryMoleskine18NULL02022-09-01false

Example Output

product_namepricefinal_price
Desk Lamp39.539.5
Ergonomic Chair Pro12991234.05
Mechanical Keyboard Pro119119
Noise Canceling Headphones299.99254.99
Notebook Set1818
Standing Desk349349
USB-C Hub4536
Wireless Mouse24.9922.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.