Reputation: 253
Below is the Syntax used
WITH total_orders_1996 AS (SELECT
customers.customer_id,
customers.company_name,
SUM(order_details.unit_price * order_details.quantity) AS totlal_orders
FROM
customers
JOIN orders ON
customers.customer_id = orders.customer_id
JOIN order_details ON
orders.order_id = order_details.order_id
WHERE
orders.order_date >= '1996=7-01-01' and orders.order_date < '1998-01-01'
GROUP BY
customers.customer_id,
customers.company_name)
Select
customer_id ,
company_name,
totlal_orders,
Case
when totlal_orders between 0 and 1000 then 'Low'
when totlal_orders between 1001 and 5000 then 'Medium'
when totlal_orders between 5001 and 10000 then 'High'
when totlal_orders > 10000 then 'Very High'
End from total_orders_1996
Order by customer_id ;
And I get an output Header for the case statement as shown below
How could I get the case header as shown below
Upvotes: 0
Views: 734
Reputation: 6094
All you need to do is add a column alias at the end of your case statement
SELECT customer_id,
company_name,
totlal_orders,
CASE
WHEN totlal_orders BETWEEN 0 AND 1000 THEN 'Low'
WHEN totlal_orders BETWEEN 1001 AND 5000 THEN 'Medium'
WHEN totlal_orders BETWEEN 5001 AND 10000 THEN 'High'
WHEN totlal_orders > 10000 THEN 'Very High'
END as customer_group
FROM total_orders_1996
ORDER BY customer_id;
Upvotes: 1