-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , FirstName [ TEXT ] , MiddleInitial [ TEXT ] , LastName [ TEXT ] | Employees : EmployeeID [ INTEGER ] primary_key , FirstName [ TEXT ] , MiddleInitial [ TEXT ] , LastName [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Name [ TEXT ] , Price [ REAL ] | Sales : SalesID [ INTEGER ] primary_key , SalesPersonID [ INTEGER ] Sales.SalesPersonID = Employees.EmployeeID , CustomerID [ INTEGER ] Sales.CustomerID = Customers.CustomerID , ProductID [ INTEGER ] Sales.ProductID = Products.ProductID , Quantity [ INTEGER ] |
-- -- How many employees sold over 20,000 quantities of "Touring-2000 Blue, 50"?

SELECT COUNT(*) FROM ( SELECT SUM(Quantity) FROM Sales WHERE ProductID IN ( SELECT ProductID FROM Products WHERE Name = 'Touring-2000 Blue, 50' ) GROUP BY Quantity, SalesPersonID HAVING SUM(Quantity) > 20000 );