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

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter