Find Top 3 Customers by Order Count
Customers Table:

Orders Table:

Query Explanation:
"Top 3 customers" → we use TOP 3.
"By order count" → we use COUNT(o.OrderID) and sort using ORDER BY TotalOrders DESC.
The JOIN connects customer data with their orders.
GROUP BY ensures we count per customer.
SQL Query:
USE Techsolve;
SELECT TOP 3
c.CustomerID,
c.Name,
COUNT(o.OrderID) AS TotalOrders
FROM
Customers c
JOIN
Orders o ON c.CustomerID = o.CustomerID
GROUP BY
c.CustomerID, c.Name
ORDER BY
TotalOrders DESC;
Output:

