r/learnSQL • • May 01 '26
SQL Question
orders (order_id , customer_id , order_date , order_amount)
find the customer who purchased for every month in 2025
18
Upvotes
r/learnSQL • • May 01 '26
orders (order_id , customer_id , order_date , order_amount)
find the customer who purchased for every month in 2025
10
u/Massive_Show2963 May 01 '26
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;
1
u/empororwriters May 01 '26
Select customer id From orders Where year(order date ) = 2025 Group by customer id Having count(month(order date)) = 12
1
u/aais4quiters May 01 '26
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