Sobes.tech
Middle+

SQL task: write a query to output Customer ID, Customer Name, Customer City for customers whose total quantity in January 2025 is more than 50.

sobes.tech AI

Answer from AI

sql SELECT c.CustomerID, c.CustomerName, c.CustomerCity FROM Customers c JOIN Orders o ON c.CustomerID = o.CustomerID JOIN OrderDetails od ON o.OrderID = od.OrderID WHERE o.OrderDate >= '2025-01-01' AND o.OrderDate < '2025-02-01' GROUP BY c.CustomerID, c.CustomerName, c.CustomerCity HAVING SUM(od.Quantity) > 50;


In this query, we join the customers, orders, and order details tables, filter by date in January 2025, group by customers, and select only those with a total quantity greater than 50.