Number of Customers Who Have Placed an Order in the Last 30 Days

The number of customers who have placed an order in the last 30 days can be found by querying the orders table and counting the number of customer_id entries where the order_date is within the last 30 days.

Problem

Write a query that returns the number of customers who have placed an order in the last 30 days.
Example input:
orders table:
customer_id | order_date
1 | 2019-01-15
2 | 2019-02-03
3 | 2019-02-10
4 | 2019-03-02
Example output:
3

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT COUNT(*)
FROM orders
WHERE order_date > DATE_SUB(NOW(), INTERVAL 30 DAY);

/*

The above query is optimal because it uses the DATE_SUB function to get the date 30 days ago and then uses the WHERE clause to filter the results to only include orders that were placed after that date.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of how to use the DATE_SUB function to get the date 30 days ago. The candidate's solution is also efficient because it uses the WHERE clause to filter the results.

Evaluated at: 2022-11-04 23:15:31