Stock status

conditional logic

Stock status

Amazon SQL Interview Question

Amazon's fulfillment team wants a simple stock label next to each product on its inventory dashboard.

Show the product_name, stock_quantity and label as stock_status for every product. The label is "Out of stock" when there are no units, "Low stock" for 1 to 19 units, and "In stock" for 20 or more units.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer
  • Data Scientist

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_namestock_quantitystock_status
Desk Lamp80In stock
Ergonomic Chair Pro5Low stock
Mechanical Keyboard Pro40In stock
Noise Canceling Headphones0Out of stock
Notebook Set0Out of stock
Standing Desk12Low stock
USB-C Hub200In stock
Wireless Mouse150In stock

Explanation

The Noise Canceling Headphones and Notebook Set have no units, so they are Out of stock. The Ergonomic Chair Pro has 5 units and the Standing Desk has 12, so both are Low stock. Everything else has 20 or more units.

The example above is a small slice of the data. Your query runs against the full tables.