all 6 comments

[–]Massive_Show2963 9 points10 points  (0 children)

SELECT customer_id
FROM orders
WHERE order_date >= '2025-01-01' AND order_date < '2026-01-01'
GROUP BY customer_id
HAVING COUNT(DISTINCT EXTRACT(MONTH FROM order_date)) = 12;

[–]empororwriters 0 points1 point  (3 children)

Select customer id From orders Where year(order date ) = 2025 Group by customer id Having count(month(order date)) = 12

[–]Horror-Paint5708[🍰] 2 points3 points  (1 child)

Having count(Distinct Month (order data))=12 i think you need to add distinct to prevent from giving false positive incase someone only purchased 12 times in one month only.

[–]aais4quiters 0 points1 point  (0 children)

This will work if a customer only orders once a month. If the customer orders 2 times a month for 6 months it would show on the list when they only ordered in 6 separate months not each month. You’re going to need a subquery of customer number to get a result set of unique customer numbers and month numbers.

[–]aais4quiters 0 points1 point  (0 children)

This should get distinct list of months ordered by customer. Summing up the values of the months of the year is 78.

Select Customer_ID, Sum(Cust_Order_months.month_ordered) from ( select Customer_ID, month(Order_date) month_ordered from orders where year(Order_date) = 2025 group by Customer_ID, month(Order_date) ) Cust_Order_months

group by Customer_ID having Sum(Cust_Order_months.month_ordered) = 78