How can you find customers who have data for all 12 months in a year using SQL?
1Times asked
Sep 2026Last seen
Sep 2026First seen
💡 Model Answer
You can group the sales data by customer_id and count the distinct months in the target year. A customer qualifies if that count equals 12. Example:
SELECT customer_id
FROM sales
WHERE YEAR(sale_date) = 2023
GROUP BY customer_id
HAVING COUNT(DISTINCT MONTH(sale_date)) = 12;
This query filters to the year, groups by customer, and keeps only those with a distinct month count of 12, meaning they have at least one sale in every month of 2023.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500