Home › Interview Questions › Given a table where a business has multiple custom…

Given a table where a business has multiple customers, write a SQL query that returns each customer ID and the total number of orders they placed in 2025, filtering only customers with more than five orders.

🟡 Medium Coding Junior level
1Times asked
May 2026Last seen
May 2026First seen

💡 Model Answer

The solution is the same as the previous examples:

SELECT customer_id,

   COUNT(*) AS total_orders

FROM Orders

WHERE YEAR(order_date) = 2025

GROUP BY customer_id

HAVING COUNT(*) > 5;

This groups orders by customer, counts them, and keeps only those groups where the count exceeds five. The query is efficient if an index exists on order_date or a composite index on (order_date, customer_id).

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