Screen Link:
My Code:
%%sql
WITH
countries AS
(
SELECT
CASE
WHEN (SELECT COUNT(*)
FROM customer
WHERE country = cus.country) = 1 THEN 'Other'
ELSE cus.country
END AS country_name,
cus.customer_id,
il.*
FROM invoice_line AS il
INNER JOIN invoice AS inv ON inv.invoice_id = il.invoice_id
INNER JOIN customer AS cus ON cus.customer_id = inv.customer_id
)
Hi, can somebody explain how does the CASE statement on the code above assigned the ‘Other’ to the countries. I’m really confuse. Thanks