Home β€Ί Interview Questions β€Ί Write a SQL query that returns each customer ID an…

Write a SQL query that returns each customer ID and the total number of orders they placed in 2025, accounting for customers who may place multiple orders on the same day.

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

πŸ’‘ Model Answer

The fact that a customer can place multiple orders on the same day does not change the aggregation logic. The query remains:

SELECT customer_id,

   COUNT(*) AS total_orders

FROM Orders

WHERE order_date >= '2025-01-01' AND order_date < '2026-01-01'

GROUP BY customer_id

HAVING COUNT(*) > 5;

COUNT(*) counts every row, so multiple orders on the same day are all included. If you only wanted distinct orders per day, you would need a subquery or DISTINCT, but the requirement is to count all orders.

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