For each customer ID, write a SQL query that returns the total number of orders they placed in 2025, but only if that total is greater than five.
1Times asked
May 2026Last seen
May 2026First seen
💡 Model Answer
Use GROUP BY to aggregate per customer and HAVING to filter the count:
SELECT customer_id,
COUNT(*) AS total_ordersFROM Orders
WHERE YEAR(order_date) = 2025
GROUP BY customer_id
HAVING COUNT(*) > 5;
This returns a row for each customer with more than five orders in 2025. The query runs in linear time relative to the number of orders in the table.
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 — invisible to screen sharing.
Get Assisting AI — Starts at ₹500