Big orders or a loyal customer

logical operators

Big orders or a loyal customer

Best Buy SQL Interview Question

Best Buy's loyalty team is choosing orders to feature in a thank-you campaign. An order qualifies if it was completed and it was either worth more than 3000 or placed by customer 1, the longest-standing customer in the data.

List the order_id, customer_id and amount of every qualifying order.

Asked of

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

ordersTable35 rows

Column NameType
order_idBIGINT
customer_idBIGINT
order_dateDATE
statusVARCHAR
amountDOUBLE

ordersExample Input

order_idcustomer_idorder_datestatusamount
100112024-01-05completed120.5
100222024-01-07completed2400
100312024-01-11completed89.99
100432024-01-15canceled45
100542024-01-18completed610.75
100622024-01-22completed1850.25
100752024-01-29completed3200
100812024-02-02refunded75
100962024-02-06completed55.4
101032024-02-09completed132.6

Example Output

order_idcustomer_idamount
10011120.5
1003189.99
100753200

Explanation

Orders 1001 and 1003 qualify because they were completed and placed by customer 1. Order 1007 qualifies because it was completed and is worth 3,200. Order 1008 also belongs to customer 1, but it was refunded, so it does not qualify.

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