Get customers who have made a purchase in the last 30 days

To get customers who have made a purchase in the last 30 days, write a SQL query that returns all customers with a purchase_date within the last 30 days.

Problem

Write a SQL query that returns all customers who have made a purchase in the last 30 days.
Example input:
customer_id | purchase_date
1 | 2020-01-01
2 | 2020-02-15
3 | 2020-03-01
Example output:
customer_id | purchase_date
2 | 2020-02-15
3 | 2020-03-01

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT customer_id, purchase_date
FROM customers
WHERE purchase_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)

/*

The solution above is optimal because it uses the DATE_SUB function to subtract 30 days from the current date.
This is optimal because it will always return the correct results, regardless of the current date.

*/

A.I. Evaluation of the Solution

The solution above is a good solution that demonstrates a level of completeness and solves the problem. The approach is also good, using the DATE_SUB function to subtract 30 days from the current date. This is optimal because it will always return the correct results, regardless of the current date.

Evaluated at: 2022-11-18 14:16:25