Orders per calendar month

dates

Orders per calendar month

Walmart SQL Interview Question

Walmart's fulfillment centers plan staff a month ahead, so the operations team wants to see how many online orders arrive each month.

Count the orders placed in each month, whatever their status. Show the first day of the month as order_month, as a date such as 2024-01-01 for January 2024, and the count as order_count. Sort the rows by order_month, earliest first.

Asked of

  • Data Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer
  • Data 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_monthorder_count
2024-01-017
2024-02-013

Explanation

Seven orders in the example were placed in January 2024, including one that was canceled, so 2024-01-01 has a count of 7. The remaining three orders were placed in February 2024.

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