Toy 2

PHOTO EMBED

Sat Jul 29 2023 01:11:22 GMT+0000 (Coordinated Universal Time)

Saved by @kentrickfelix #mysql

WITH CustomerSales AS (
	SELECT p.customerNumber, customerName, salesRepEmployeeNumber, SUM(amount) as total
	FROM payments p
	JOIN customers c ON p.customerNumber = c.customerNumber
	GROUP BY customerNumber
)
SELECT cs.salesRepEmployeeNumber, e.lastName, e.firstName, SUM(total) AS total
FROM CustomerSales cs
JOIN employees e ON cs.salesRepEmployeeNumber = e.employeeNumber
GROUP BY salesRepEmployeeNumber
ORDER BY total DESC
LIMIT 5;
content_copyCOPY