Preview:
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;
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