WITH CustomerPurchases AS ( SELECT c.customerNumber, c.customerName, SUM(amount) AS total FROM customers c LEFT JOIN payments p ON c.customerNumber = p.customerNumber GROUP BY c.customerNumber, c.customerName ) SELECT customerName, total, CASE WHEN total >= 100000 THEN "high-valued" WHEN total < 100000 AND total > 0 THEN "medium-valued" ELSE "low-valued" END AS priority FROM CustomerPurchases ORDER BY total DESC;
Preview:
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