Toy 1

PHOTO EMBED

Sat Jul 29 2023 00:32:35 GMT+0000 (Coordinated Universal Time)

Saved by @kentrickfelix #mysql

WITH CustomerPayments 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 CustomerPayments
ORDER BY total DESC;
content_copyCOPY